Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Created May 29, 2016 03:19
Show Gist options
  • Save henriquegogo/0d3a484990410d219373fcbc25515d1b to your computer and use it in GitHub Desktop.
Save henriquegogo/0d3a484990410d219373fcbc25515d1b to your computer and use it in GitHub Desktop.
Generic node/express application based on routes and static files
var path = require('path');
var fs = require('fs');
var express = require('express');
var app = express();
// Load all route files
var routes_path = path.join(__dirname, 'routes');
fs.readdirSync(routes_path).forEach((route) => {
app.use('/' + route.slice(0,-3), require(routes_path + '/' + route) );
});
// Declare static folder
app.use(express.static(path.join(__dirname, 'public')));
// Run application
app.listen(3000);
console.log('Application running on port 3000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment