Node js project boilerplate using GraphQL and typescript
npx create-nodejs-boilerplate <project-name> --template graphQL
Clone the repository:
git clone https://github.com/djibril6/graphql-nodejs-boilerplate.git
# Then
npx rimraf ./.git
Then create a new .env
file in the project root directory and copy the .env.exemple file content (this step not necessary in the project in installed with create-node-js-boilerplate
).
Install the dependencies for the project:
npm install
#Or
yarn
Edit the .env
file by adding the corrects value for each field.
- NoSQL database: MongoDB object data modeling using Mongoose
- Email service: Email API service Sendgrid
- Validation: request data validation using Joi
- Logging: using winston and morgan
- Testing: unit and integration tests using Jest
- Process management: advanced production process management using PM2
- Security: set security HTTP headers using helmet
- Santizing: sanitize request data against xss and query injection
- CORS: Cross-Origin Resource-Sharing enabled using cors
- Compression: gzip compression with compression
- CI: continuous integration with Travis CI
- Docker support
- Code coverage: using coveralls
- Code quality: with Codacy
- Git hooks: with husky and lint-staged
- Linting: with ESLint and Prettier
- Editor config: consistent editor configuration using EditorConfig
src\
|--config\ # Environment variables and global configurations
|--controllers\ # All Route controllers (and Business logic)
|--datasources\ # Data source Classes for graqhql
|--graphql\ # All GraphQl logics (schema, resolver, server config)
|--middlewares\ # All Custom middlewares
|--models\ # All Mongoose models
|--types\ # All TypeScript shared interfaces and enums
|--utils\ # Utility classes and functions
|--validations\ # All data validation logics
|--setup.ts # Express app setup
|--index.ts # App entry point
test\
|--integration\ # integration test files
|--utils\ # utilty functions for test
|--services\ # All usefull services for test
The graphql documentation of the application is available on http://localhost:{PORT}/v1/docs
.
We are using an access and refresh token system.
Logging should be done with the logger module (do not use console.log()
) located in src/config/logger.js
, according to the following severity levels:
import { config, logger } from '<path to src>/config';
logger.error('message'); // level 0
logger.warn('message'); // level 1
logger.info('message'); // level 2
logger.http('message'); // level 3
logger.verbose('message'); // level 4
logger.debug('message'); // level 5