Express Web Server

Overview


The express package contains the code necessary to build a simple webserver using Node.js. This page details the steps to setting up the server.

Setup


The webserver in this example is built on the express framework, which needs to be installed first.


npm install express
                    

In addition, the example uses the body-parser library to parse the contents of the HTML requests into Javascript objects. This library is not strictly needed to run a webserver, but is highly recommended.


npm install body-parser
                    

Example Code


This is a simple script that runs a webserver.


const express = require('express')
const bodyParser = require('body-parser');

const app = express();
const port = 80;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
	extended: false
})); 


app.get('/index.html', (req, res) => {
  res.send(`Hello World`);
});