support@codebucket.net

Run the first application in ExpressJs

Run the first application in ExpressJs

K. M. Shawkat Zamil | October 16, 2022

Hello Developers,

In this tutorial, I will show you how you run your first application in ExpressJs. First, you have to install NodeJs in your working environment. Follow the tutorial: (Tutorial Link)

 

First, create a folder and open the command prompt. Then run the below command: 

 

npm init --y

 

Then create a file named index.js. After that paste the below code into the index.js file. Run the below command first.

 

npm install express --save

 

/index.js

var express = require('express');

app = express();

app.get("/", function name(request, response) {
    response.send("Hello Express Js");
})

app.listen(8000, function () { 
    console.log('Server Run Success');
});

 

Here first we call the express module. Then we call the get() method to call the URL. a callback function is also called to show a line in the browser. Then call the listen() method to set the port. After that run the below command in the command line.

 

node index.js

 

Run the below line in the browser:

 

http://localhost:8000/

 

Hope this might help in the development journey.

 

Read More: Learn some important functions in ExpressJs

K. M. Shawkat Zamil

K. M. Shawkat Zamil

Senior Software Engineer

I am a Senior Software Engineer in a reputed company in Bangladesh. I am a big fan of Laravel, PHP Programming, MSSQL Server, MySql, JavaScript, and lots more. I love to help people who are especially eager to learn. I believe in patience and motivation.