Skip to content

Instantly share code, notes, and snippets.

@DannyDelott
Created May 29, 2015 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannyDelott/c91eb480e1c8d08fd928 to your computer and use it in GitHub Desktop.
Save DannyDelott/c91eb480e1c8d08fd928 to your computer and use it in GitHub Desktop.
Simple node server
/* *****************
* Require Imports *
* *****************/
var express = require('express');
var path = require('path');
/* ***********************
* Initialize Middleware *
* **********************/
// Instantiate the express object
var app = express();
// Use the static assets from the same directory as this server.js file
app.use(express.static(path.resolve("./")));
/* **************
* GET Requests *
* **************/
// index.html
app.get('/', function(req, res) {
res.sendFile('index.html');
});
/* ******************
* Start the server *
* ******************/
var port = process.env.PORT || 8000;
var server = app.listen(port, function() {
console.log('Listening on port:', port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment