Skip to content

Instantly share code, notes, and snippets.

@marlun78
Last active June 14, 2021 06:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marlun78/10755657 to your computer and use it in GitHub Desktop.
Save marlun78/10755657 to your computer and use it in GitHub Desktop.
Super simple express sever for serving static content
/**
* Simple express sever
* Copyright (c) 2014, marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* Assumes this folder structure
* /public
* /server
*
* Express: http://expressjs.com
*/
var app, server,
express = require('express'),
path = require('path'),
host = process.env.HOST || '127.0.0.1',
port = process.env.PORT || 3000,
root = path.resolve(__dirname, '..');
app = express();
app.use(function(req, res, next) { console.log(req.url); next(); });
app.use(express.static(root + '/public'));
server = app.listen(port, host, serverStarted);
function serverStarted () {
console.log('Server started', host, port);
console.log('Root directory', root);
console.log('Press Ctrl+C to exit...\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment