What is EXPRESS.JS?

What is EXPRESS.JS?

Express.js, it is a web framework and based on the core Node.js http module and Connect components. We also called middleware for those component. In other word It is extensible,also minimalist web framework built for the Node.js ecosystem. We able to create a web server that is more flexible, readable and maintainable using Express.

How to setup express?

  1. Create a directory that you wish to hold this project.
  2. Open your terminal and go inside to that created directory.
  3. Then initialize the NPM to create package.json file.
  4. After install Express(as a dependency).
How setup express

Hello World Example!

  1. Create a new file and rename it as server.js (this file hold the code)
  2. In that file write below code.
‘Hello world’ example
  1. To start the server run below code in terminal
To start the server

Now you can see the output. It display ‘hello world’ in screen on localhost:3000 .

Output

How it works?

In the first line of the code require express that installed earlier part(via NPM). Then setup our express application in second line.

First Two lines

Then move to the ‘app.listen()‘ . It tells server to listening for connection on port 3000.This is the reason Output display in ‘localhost:3000’. When server is listen to the port callback called and logs ‘express intro running on localhost:3000’ in terminal.

app.listen()

app.get() is responsible for create route handler to listen for GET request.In this case listening get request on localhost:3000. Similarly If you want to listen POST request , then we can use app.post().

Thank You!

Leave a comment