Creating a server using the http library

First up, we'll load in the http module. So, let's make a constant called http, which is a built-in Node module so there's no need to install it. We can simply enter require('http'), just like this:

const path = require('path');const http = require('http');const express = require('express');const socketIO = require('socket.io');

From here, we'll create a server using this http library. Just below our app variable, let's make a variable called server. We'll call http.createServer:

const path = require('path');const http = require('http');const express = require('express');const socketIO = require('socket.io');const publicPath = path.join(_dirname, '../public');const port = process.env.PORT || 3000; ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.