README
Express Zero Config
Create an express app with a default configuration. Based on the official express generator.
Install
npm install -S express-zero-config
#or
yarn add express-zero-config
Quick Start:
const ezc = require('express-zero-config');
const router = ezc.createRouter();
router.get('/', (req, res, next) => {
res.json({
message: 'Hello World!'
})
});
ezc.startServer(router); // startServer parameters: (express.Router, port_number)
For more advanced usage and configuration options see the Examples section.
Included Defaults:
- Handlebars view engine
- 404 and uncaught error handlers
- middleware:
- morgan (development logger)
- cookie-parser
- body-parser
on github express-zero-config
If you get some use out of express-zero-config
please star the repo on github.
Make an issue on github to report bugs and request new features.
Examples
Source code for the below examples is available in the examples
folder.
Usage with views and static configuration
const path = require('path');
const ezc = require('express-zero-config');
const router = ezc.createRouter();
router.get('/', (req, res, next) => {
res.json({
message: 'Hello World!'
})
});
const app = ezc.createApp({
router,
view_path: path.join(__dirname, 'views'),
static_dir: path.join(__dirname, 'public')
});
const server = ezc.createServer(app); // createServer parameters: (express app, port_number)
server.start();
Usage with multiple routers and middleware
const path = require('path');
const session = require('express-session');
const passport = require('passport');
const ezc = require('express-zero-config');
const auth = require('./auth'); // Exports an express router
const api = require('./api'); // Exports an express router
const router = ezc.createRouter();
router.use('/auth', auth);
router.use('/api/v1', api);
const app = ezc.createApp({
router,
use: [
session({ secret: process.env.SESSION_SECRET }),
passport.initialize(),
passport.session()
],
view_path: path.join(__dirname, 'views'),
static_dir: path.join(__dirname, 'public')
});
const server = ezc.createServer(app);
server.start();