Open In App

How to set up your Node.js and Express development environment?

Last Updated : 28 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to learn how to set up your NODE JS and Express JS development environments. Node JS and Express JS development environments are used to write the code for the server side. Server-side code is responsible for handling HTTP requests and API endpoints of your application. When the client makes any request, the server-side code responds with data from the database.

Node JS is an open-source and cross-platform runtime environment built on Chrome’s V8 JavaScript engine for executing JavaScript code outside of a browser. It provides an event-driven, non-blocking (asynchronous) I/O and cross-platform runtime environment for building highly scalable server-side applications using JavaScript.

Express.js is a small framework that works on top of Node.js web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing. It adds helpful utilities to Node.js HTTP objects and facilitates the rendering of dynamic HTTP objects.

Install Node JS

Node JS is Chrome’s V8 engine for executing Javascript code directly on your machine without a browser. Before using Node JS, we need to install it on our local machine. For that, we can visit the official website of Node JS or directly download it from the given links.

We recommend that you download the LTS version. LTS stands for long-term stable version of NODE JS. Now download according to operating system installed in your machine.

  • WINDOWS OS
https://nodejs.org/dist/v20.10.0/node-v20.10.0-x64.msi
  • MAC OS
https://nodejs.org/dist/v20.10.0/node-v20.10.0.pkg

Install IDE (Integrated Development Environment)

IDE stands for Integrated Development Environment, which is nothing but a text editor where developers prefer to write code because it highlights syntax with different colors and has multiple extensions that help developers write code and debug smoothly. There are multiple types of IDEs used to write code; it totally depends on the choice of developer.

In this article, we will prefer to choose VS CODE (Visual Code Studio) from Microsoft, which is easy to download, install, and use on your local machine.

To download VS code on your machine, you can visit the official site, or you can download directly from the link given below. Now download your software according to the operating system installed in your machine.

  • Windows OS
https://code.visualstudio.com/docs/?dv=win64user
  • MAC OS
https://code.visualstudio.com/docs/?dv=osx
  • Linux OS
https://code.visualstudio.com/docs/?dv=linux64_deb

Initialize a project

Now that we have installed all the minimum software requirements, we have to initialize the project. This means we have to create a root directory where all the files that will be used in this project will be present, and we also need to initialize package.json to install the required modules or dependencies.

Steps to initialize project:

Step 1: Create a directory for server via following command.

mkdir root

Step 2: Initialize a project via following command.

npm init -y

Install Express JS

Now we need to install the Express JS framework, which will help us to initialize a server and also to write server-side code that is small and precise. After installing Express JS, we will be able to use the functionalities of Express JS in your project.

To install ExpressJS on your machine, we have to use the following command:

npm i express

After executing this command express will be installed in your machine and your updated dependencies will look a like:

"dependencies": {
      "express": "^4.18.2"
  }

Implement a simple program

Now we are going to implement a basic program of server-side code in which we will implement server and basic routing requests using Express JS.

Javascript




// Server.js
const express = require('express');
const app = express();
const PORT = 3000;
 
app.get('/', (req, res) => {
    res.send('Get Request Successfull');
});
 
app.listen(PORT, () => {
    console.log(`Server is established at port -> ${PORT}`);
});


Steps to run : Run the following command.

node server


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads