Getting Started With Node – Course

Installing Express

Create a new folder and switch to it using a terminal or command prompt.

cd <folder path>

Create a new node project using the following command.

npm init --y

This will create a sample package.json for your project.

To install express module, run the following command.

npm install --save express

The latest version of the express framework will be installed in your project.

Now create a new file and name it app.js.

In this file, we will write our web server using express.

const express = require('express')
const app = express();

app.listen(process.env.port || 3000);
console.log('Web Server is listening at port '+ (process.env.port || 3000));

In the code shown above, we have required the express module and created a new instance of it. In the end, we have started our Server using the listen() function.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.