CodeSolution

Please wait...

how to use express in nodeJs - Learn in 10 Minutes

@NodeJs  @ Express  @ Learn  @ use  @ Minutes  

Fast, unopinionated, minimalist web framework for Node.js

Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It facilitates the rapid development of Node based Web applications.

There are some of the core features of Express framework:?

  1. Allows to set up middleware to respond to HTTP Requests.
  2. Defines a routing table which is used to perform different actions based on HTTP Method and URL.
  3. Allows to dynamically render HTML Pages based on passing arguments to templates.

Installing Express

Firstly, install the Express framework Open terminal and run this command in a project folder 

locally install command 

npm install --save express

globally install command 

npm install -g express

--save means save express in the local project folder and -g means install express globally in your system.

After install express create a server.js file and write a code 

var express = require('express');
var app = express();
app.get('/', function (req, res) {
   res.send('Hello World');
})
app.listen(process.env.PORT || 8857, function(){console.log("App listening on port 8857");});

Save the above code and run it with the following command.

node server.js

You will see the following output −

http://localhost:8857/

Github

code Link: https://github.com/Sudarshan101/ExpressSetup

 

 

Comments 0

Reply