ES6 Nodejs Project Kickstart
Srinivas Kandukuri
Posted on October 29, 2019
Architecture
When we start new project, we all try to follow the best architecture. Architecture is the starting point to project, A bad project architecture create lot of unnecessary workload to developers and very difficult to introduce new feature to project.
here is the sample snippet of routefile
import express from 'express';
import HelperUtils from '../utils/helperUtils';
const Helperservice = new HelperUtils();
const router = express.Router();
/* This routes Serves application home page */
router.get('/', (req, res) => {
res.send('Application Running');
});
/* sample end point */
router.get('/getData', async (req, res) => {
const response = Helperservice.reverse();
res.json({
reverseString: response,
status: 'success',
statusCode: 200,
});
});
export default router;
Rule-1 : Standard folder/project architecture
Rule-2 : Best tools used
Rule-3 : Separate router file
Rule-4 : Separate service layer
Rule-5 : Babel integration
Rule-6 : Automated test cases
Rule-7 : Code coverage report
Rule-8 : Es-lint integration
Quick Start
- Make sure you have recent, stable version of nodejs in your system. Please check version before run
$ node -v
Clone or download this repository.
Run this following command in your terminal from the project folder
$ npm install
List of Commands/Tasks
Lint
Perform eslint in your project
$ npm run lint
Lint Fix
Most of the errors reported by eslint fixed by using this command
$ npm run lint-fix
Test
This will run all test cases
$ node test
Generate nyc report -- (optional command)
After testcases passed this will generate nyc report and uploads to codecov
$ node report-coverage
Build (Transpiled)
This will create '/dist' folder and converts the ES6 code into es5
$ node run build
Start nodejs server
$ node start
NPM Package Details
Build Status
Code Cov
💖 💪 🙅 🚩
Srinivas Kandukuri
Posted on October 29, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.