Created
May 29, 2016 03:19
-
-
Save henriquegogo/0d3a484990410d219373fcbc25515d1b to your computer and use it in GitHub Desktop.
Generic node/express application based on routes and static files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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