Last time we made a server using Node's built in HTTP modules. Let's see how we do that same thing, but using Express

 // server.js
var express = require('express');
var app = express();
var port = 8080;

// start the server
app.listen(port, function() {
  console.log('app started');
});

// route our app
app.get('/', function(req, res) {
  res.send('hello world!');
});

Start the server with node server.js and check it out at http://localhost:8080.

Now if you make a change to your 'hello world' string and refresh, you'll notice the changes didn't take. We actually have to restart the server everytime we make a change. That's no fun, so let's install a tool to help.

Table of Contents

    npm install nodemon --save

    Now run nodemon server.js and you never have to restart again!

    Chris Sevilleja

    173 posts

    Co-founder of Scotch.io. Slapping the keyboard until something good happens.