Skip to content

Instantly share code, notes, and snippets.

@nicroto
Created September 27, 2016 14:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save nicroto/3ebdde47490958f15d3ab59a8bf7e1cd to your computer and use it in GitHub Desktop.
Save nicroto/3ebdde47490958f15d3ab59a8bf7e1cd to your computer and use it in GitHub Desktop.
NodeJS server for a single-page app with client navigation and no backend.
'use strict';
var http = require( "http" ),
pathUtils = require( "path" ),
express = require( "express" ),
app = express(),
PORT = process.env.PORT || 5000,
appDir = pathUtils.resolve( __dirname, "client" );
app.use( express.static( appDir ) );
app.get( "*", function( req, res ) {
res.sendfile( pathUtils.resolve( appDir, "index.html" ) );
} );
http.createServer( app ).listen( PORT, function() {
console.log( "Express server listening on port " + PORT );
console.log( "http://localhost:" + PORT );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment