Skip to content

Instantly share code, notes, and snippets.

@xgenvn
Forked from nicroto/server.js
Created December 6, 2017 01:46
Show Gist options
  • Select an option

  • Save xgenvn/942f0fd5edf3dc77b250e95bae1adf4e to your computer and use it in GitHub Desktop.

Select an option

Save xgenvn/942f0fd5edf3dc77b250e95bae1adf4e 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