Serve a static file with express — example

Step 1: Install Express

cd to the your code file and on your terminal run:

npm install express

Step 2: Require Express

This is node’s way to access and use modules (i.e. code someone else wrote):

var express = require('express');

Step 3: Serve your static page

If index.html is located on the same directory as the server file, the following code will serve your index.html file:

 app.use(express.static(__dirname + '/'));

Step 4: Drink some hot cool-aid

Because your rocked it.

--

--