Boilerplate for Node.js applications
- Environment: Node.js v16.13.0
- Framework: Express.js v4.17.1
- Test framework: Mocha v7.1.0
- Database: Sequelize v5.22.4 (ORM) and PostgreSQL with node-postgres v8.7.1
We use dotenv for environment variables
Passport is used for authentication, with Local Strategy (for username and password authentication) and JWT Strategy (for token authentication) jsonwebtoken is used for creating session tokens and bcrypt for encrypting user passwords before saving to the DB.
Morgan is used to log incoming requests, combined with Winston for a super logging experience.
We use mocha, supertest and expect for writing tests. On top of that we use faker for creating realistic-looking data for tests. Tests can be run using the command npm run test
. Pre-commit is used to run tests before committing changes. Changes shouldn't be committed unless all tests are passing, but this step can be skipped using the -n
flag.
We use ESLint with eslint-config-airbnb-base plugin for linting. You can run the linter with npm run lint
. Pre-commit is used to run the linter before committing changes. Changes shouldn't be committed unless approved bt the linter, but this step can be skipped using the -n
flag.
Use the command npm run start
to run this boilerplate. We use nodemon to detect changes in the source code and update the app on the fly.
We use sequelize-cli to write and run migrations to the database. Run sequelize-cli db:migrate
to run initial migrations.
When receiving and responding to a request, the flow should be controller -> service -> model -> service -> controller -> render service. Most requests shouldn't be handled directly by controllers, instead they should be delegated to services where the business logic can be found. You can read more about this here