Skip to content

Instantly share code, notes, and snippets.

@degrammer
Created April 18, 2015 03:43
Show Gist options
  • Save degrammer/daf19158c29d41b4365c to your computer and use it in GitHub Desktop.
Save degrammer/daf19158c29d41b4365c to your computer and use it in GitHub Desktop.
Create a local express web server, serve static files inside a folder named public, open a browser in the application port
var express = require('express');
var path = require('path');
var express = require('express');
var openPage = require('open');
var packageConfig = require('./package.json');
var server = null;
(function(){
console.log("**** Starting express server ******");
this.server = express();
this.server.use('/', express.static(__dirname + '/public'));
var applicationPort = packageConfig.port === null ? 80 : packageConfig.port;
this.server.listen(applicationPort);
console.log("**** Listening at " + applicationPort + " port ****");
openPage("http://localhost:" + applicationPort);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment