generator-node-template v0.0.7
generator-node-template
A Node.js service template generator for Yeoman based on hapi
Choose your tech stack and create node.js template of api service
Tech
Database Options
- Rethinkdb with RethinkDbDash as a node.js driver
- MongoDB with mongoose as a node.js driver
Front-end Integration Option With
- handlebars - Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.
Lint Options
Containerization Platform Options
Service Libraries
- Hapi.js - A rich framework for building applications and services
- bluebird - Bluebird is a fully featured promise library with focus on innovative features and performance
- boom - HTTP-friendly error objects
- config - Node-config organizes hierarchical configurations for your app deployments.
- hapi-swagger - Auto swagger documentations generator
- joi - Object schema description language and validator for JavaScript objects
- lodash - A modern JavaScript utility library delivering modularity, performance & extras.
- winston - A multi-transport async logging library for node.js
Process Manager
- pm2 - Production process manager for Node.js apps with a built-in load balancer
Testing Libraries
- jasmine - A multi-transport async logging library for node.js
- istanbul - A JS code coverage tool written in JS
- sinon - Standalone test spies, stubs and mocks for JavaScript
Installation
The output service template supported Node.js v4+.
Make sure you have yo installed
npm install -g yo
Install the generator globally
npm install -g generator-node-template
Run: generator-node-template and choose your preferences
yo node-template
Project Structure
.
├── config
│ ├── idefault.json
│ ├── development.json
│ ├── prod.json
├── lib
│ ├── server.js
│ └── data
│ └── api
│ └── └── models
│ └── ├── productsEndpoints.js
│ └── ... // more endpoints
│ └── infrastructure
│ └── └── hapi
│ └── └── ├── authenticationPlugin.js
│ └── └── ├── extentions.js
│ └── ├── logger.js
│ └── logic
│ └── ├── productsHandler.js
│ └── ├── authentication.js
├── templates
├── public
├── tests
│ └── integrations
│ └── units
├── index.js
├── package.json
└── readme.md
Database layer (lib/data)
index.js file expose all db models and initialize them
Logic layer (lib/logic)
contains all logics code for the endpoints
API layer (lib/api)
contains all api models and endpoints defenitions
Infrastructure code (lib/infrastructure)
contains infrastructure code (e.g: logger)
Authentication code (lib/logic/authentication.js)
authentications.js contains authenticate function which will be called with the token value for each request
Integration tests code (tests/integrations)
contains all integration tests
Units tests code (tests/units)
contains all unit tests
Q&A
- How to run tests
npm test
- How to run lint
npm lint
- How to run the service
npm start
- How to run the service using pm2
pm2 start ecosystem.json --env={env_name}
- How to work with several environment with config module
Development
Want to contribute? Great! Clone the repository and push your changes
How to run it locally
Run the following command on the root project
npm link
Then every time when you run the install command it will take it from your local source code
Todos
- Add support of new databases
- Add tests for the generator
- Add support of new Lints
License
MIT