Skip to content

Instantly share code, notes, and snippets.

@aquasmit
Last active May 17, 2016 02:49
Show Gist options
  • Save aquasmit/3caf0f19cb1d9f02924e486701c54dd8 to your computer and use it in GitHub Desktop.
Save aquasmit/3caf0f19cb1d9f02924e486701c54dd8 to your computer and use it in GitHub Desktop.
Node.js server with express

###Using Node.js as server with Express

Step 1: Install Express $ npm install express

Step 2: Create a file named server.js with the following code:

var express = require('express');
var app = express();
app.use(express.static(__dirname)); //serve static files
app.get('/', function (req, res) {
  res.send('Hello World!');
});
app.listen(3000, function () {
  console.log('Server listening on port 3000!');
});

Step 3: Spinup server.js

$ node server.js

You can got to http://localhost:3000 or http://localhost:3000/yourfile.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment