Skip to content

Instantly share code, notes, and snippets.

@garris
Last active August 29, 2015 14:01
Show Gist options
  • Save garris/37104cfb69406d575c28 to your computer and use it in GitHub Desktop.
Save garris/37104cfb69406d575c28 to your computer and use it in GitHub Desktop.
simple node+express app to host static SPA file over http
var express = require('express')
,app = express()
,_ = require('underscore')
,util = require('util')
,os = require('os');
var rootDir = __dirname + '/app'
,port = 3000;
app.use(express.static(rootDir));
app.listen(port);
//===================
console.log('Serving files from: '+rootDir)
console.log('Listening on: ' + getAddresses() + ':' + port + '');
console.log('Press Ctrl + C to stop.');
function getAddresses(){
var interfaces = os.networkInterfaces(),
addresses = [];
_.each(interfaces,function(net){
_.each(net,function(address){
if (address.family == 'IPv4' && !address.internal) addresses.push(address.address);
})
})
return addresses;
}
@garris
Copy link
Author

garris commented May 9, 2014

SPA server

This will serve index.html at the current directory path + /app.

To run, enter: node server.js

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