What is Express.js?

Answer: Simply put, express.js is a web framework that could be used with Node.js.

Express.js can start an application server listening on a port in your machine.

Express.js starts the application in a single thread and handles HTTP methods like GET, POST, DELETE, etc., asynchronously.

Even, if you have just started with Express.js, you can build a simple server in a couple of minutes.

Express.js uses inbuilt http protocol for web requests and responses. Express.js provide wrappers for intercepting requests and preparing responses thus making coding web server simple.

You can adopt architectures like MVC easily using Express.js.

Express.js handle errors gracefully. Even if errors occur, express do not make the web server go down.

A simple web server using Express.js

As we have already mentioned that it is just a couple of minutes required to create a web server using Express.js, let us create one.

app.js

</>
Copy
var express = require('express')
var app = express()

app.get('/', function (req, res) {  
  res.send('Node.js Express Tutorial by TUTORIALKART')
  res.end()
})

app.listen(8000)

When you run this using node command, node app.js, and do not find any errors, the server is up and running.

Open a browser and hit the url http://localhost:8000/.

What is Express.js?