├── template ├── .gitignore ├── {{@@Name@@}} │ ├── .eslintignore │ ├── src │ │ ├── views │ │ │ ├── templates │ │ │ │ ├── errors │ │ │ │ │ ├── 404.handlebars │ │ │ │ │ ├── 500.handlebars │ │ │ │ │ └── {{@@Name@@}}.handlebars │ │ │ │ └── index.handlebars │ │ │ ├── partials │ │ │ │ └── head.handlebars │ │ │ └── layouts │ │ │ │ └── basic.handlebars │ │ ├── static │ │ │ └── js │ │ │ │ └── {{@@Name@@}}.js │ │ ├── middlewares.js │ │ ├── inits │ │ │ └── index.js │ │ ├── routes │ │ │ └── public.js │ │ ├── db │ │ │ └── mongo.js │ │ ├── app.js │ │ └── handlers.js │ ├── .babelrc │ ├── .eslintrc.json │ └── package.json └── README.md └── project.json /template/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /project.json: -------------------------------------------------------------------------------- 1 | { 2 | "Name": "myproject" 3 | } 4 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | static 3 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/views/templates/errors/404.handlebars: -------------------------------------------------------------------------------- 1 | 404 2 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/views/templates/errors/500.handlebars: -------------------------------------------------------------------------------- 1 | 500 Error 2 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/static/js/{{@@Name@@}}.js: -------------------------------------------------------------------------------- 1 | $(document).ready(() => { 2 | }); 3 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/views/templates/errors/{{@@Name@@}}.handlebars: -------------------------------------------------------------------------------- 1 | {{@@Name@@}} error 2 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/views/templates/index.handlebars: -------------------------------------------------------------------------------- 1 |
2 | {{@@Name@@}} 3 |
4 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": ["transform-object-rest-spread"] 4 | } 5 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/middlewares.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | checkLoggedIn: (req, res, next) => next(), 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/inits/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | init(app, callback) { 3 | callback(); 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/routes/public.js: -------------------------------------------------------------------------------- 1 | const router = require('express').Router(); 2 | 3 | module.exports = router; 4 | 5 | router.get('/', (req, res) => res.render('index')); 6 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb-base", 3 | "rules": { 4 | "semi": ["error", "always"], 5 | "quotes": ["error", "single"], 6 | "linebreak-style": "off", 7 | "indent": ["error", 4], 8 | "no-underscore-dangle": "off", 9 | "no-console": "off", 10 | "no-unused-vars": ["error", {"argsIgnorePattern": "next"}] 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/views/partials/head.handlebars: -------------------------------------------------------------------------------- 1 | 2 | {{@@Name@@}} 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/views/layouts/basic.handlebars: -------------------------------------------------------------------------------- 1 | 2 | {{> head}} 3 | 4 | 11 |
12 | {{{body}}} 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /template/README.md: -------------------------------------------------------------------------------- 1 | This is a boilr template for a basic nodeJS app. 2 | This works on delimiter {{@@@@}} built on my custom fork of boilr. 3 | 4 | ## Setting up Development Environment 5 | 6 | ``` 7 | cd {{@@Name@@}}/{{@@Name@@}} 8 | ``` 9 | 10 | ``` 11 | npm install 12 | ``` 13 | 14 | In one Tab 15 | ``` 16 | npm run build-dev 17 | ``` 18 | 19 | In Second Tab 20 | ``` 21 | npm run run-dev 22 | ``` 23 | 24 | In Third Tab 25 | ``` 26 | npm run copy-statics-dev 27 | ``` 28 | 29 | Before committing 30 | 31 | ``` 32 | npm run lint 33 | ``` 34 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/db/mongo.js: -------------------------------------------------------------------------------- 1 | const config = require('config'); 2 | const { MongoClient, ObjectID, MongoError } = require('mongodb'); 3 | 4 | let db; 5 | 6 | function getConnection(callback) { 7 | if (db) { return callback(db); } 8 | MongoClient.connect(config.get('database.mongo.url'), (err, database) => { 9 | if (err) { throw err; } 10 | db = database; 11 | return callback(db); 12 | }); 13 | return null; 14 | } 15 | 16 | function toObjectId(id) { 17 | if (ObjectID.isValid(id)) { return ObjectID(id); } 18 | return id; 19 | } 20 | 21 | function newObjectId() { 22 | return ObjectID(); 23 | } 24 | 25 | module.exports = { 26 | getConnection, 27 | toObjectId, 28 | MongoError, 29 | newObjectId, 30 | }; 31 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{@@Name@@}}", 3 | "version": "1.0.0", 4 | "description": "{{@@Name@@}}", 5 | "main": "./dist/app.js", 6 | "scripts": { 7 | "lint": "./node_modules/.bin/eslint src --fix", 8 | "build": "./node_modules/.bin/babel src -d dist", 9 | "build-dev": "./node_modules/.bin/babel src -d dist -w", 10 | "copy-statics": "cpx \"./src/views/**/*\" ./dist/views", 11 | "copy-statics-dev": "cpx \"./src/views/**/*\" ./dist/views --watch", 12 | "run-dev": "./node_modules/.bin/nodemon ./dist/app.js" 13 | }, 14 | "author": "Arpit Bhayani", 15 | "license": "ISC", 16 | "dependencies": { 17 | "body-parser": "^1.17.2", 18 | "config": "^1.26.2", 19 | "cookie-parser": "^1.4.3", 20 | "cpx": "^1.5.0", 21 | "express": "^4.15.4", 22 | "express-handlebars": "^3.0.0", 23 | "mongodb": "^2.2.31", 24 | "superagent": "^3.6.0" 25 | }, 26 | "devDependencies": { 27 | "babel-cli": "^6.26.0", 28 | "babel-core": "^6.26.0", 29 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 30 | "babel-preset-es2015": "^6.24.1", 31 | "eslint": "^4.12.0", 32 | "eslint-config-airbnb-base": "^12.0.0", 33 | "eslint-plugin-import": "^2.7.0", 34 | "nodemon": "^1.12.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const app = express(); 4 | const initializer = require('./inits'); 5 | const bodyParser = require('body-parser'); 6 | const exphbs = require('express-handlebars'); 7 | const handlers = require('./handlers'); 8 | 9 | const publicRoutes = require('./routes/public'); 10 | 11 | /* Handlebars */ 12 | app.set('views', './dist/views/templates'); 13 | app.engine('handlebars', exphbs({ 14 | defaultLayout: 'basic', 15 | layoutsDir: './dist/views/layouts', 16 | partialsDir: './dist/views/partials', 17 | })); 18 | app.set('view engine', 'handlebars'); 19 | 20 | app.use(bodyParser.urlencoded({ extended: false })); 21 | app.use('/static', express.static('./dist/static')); 22 | app.use(require('cookie-parser')()); 23 | 24 | function registerRoutes() { 25 | app.use('/', publicRoutes); 26 | } 27 | 28 | initializer.init(app, () => { 29 | registerRoutes(); 30 | 31 | app.use(handlers.notFoundHandler); 32 | 33 | app.use(handlers.{{@@Name@@}}ErrorHandler); 34 | app.use(handlers.logError); 35 | app.use(handlers.mongoErrorHandler); 36 | app.use(handlers.errorHandler); 37 | 38 | const PORT = 8082; 39 | app.listen(PORT, () => { 40 | console.log(`{{@@Name@@}} listening on port ${PORT}!`); 41 | }); 42 | }); 43 | 44 | process.on('SIGINT', () => { 45 | process.exit(0); 46 | }); 47 | -------------------------------------------------------------------------------- /template/{{@@Name@@}}/src/handlers.js: -------------------------------------------------------------------------------- 1 | const { MongoError } = require('./db/mongo'); 2 | 3 | module.exports = { 4 | {{@@Name@@}}ErrorHandler(err, req, res, next) { 5 | const { out } = req.query; 6 | const index = err.message.indexOf('::'); 7 | if (index !== -1) { 8 | const type = err.message.substring(0, index); 9 | const error = err.message.substring(index + 2); 10 | 11 | if (out === 'json') { 12 | return res.status(400).send({ 13 | error, 14 | type, 15 | }); 16 | } 17 | return res.status(400).render('errors/{{@@Name@@}}', { 18 | type, 19 | error, 20 | }); 21 | } 22 | return next(err); 23 | }, 24 | 25 | logError(err, req, res, next) { 26 | console.error(err.message, err.stack); 27 | return next(err); 28 | }, 29 | 30 | mongoErrorHandler(err, req, res, next) { 31 | if (err instanceof MongoError) { 32 | console.error(err.message, err.stack); 33 | return res.status(500).render('errors/500'); 34 | } 35 | return next(err); 36 | }, 37 | 38 | notFoundHandler(req, res) { 39 | return res.status(404).render('errors/404'); 40 | }, 41 | 42 | errorHandler(err, req, res, next) { 43 | return res.status(500).render('errors/500'); 44 | }, 45 | }; 46 | 47 | --------------------------------------------------------------------------------