Skip to content

keustps/node-api-base

Repository files navigation

Node API Base Project

Features

  • Configuration module with dotenv package.
  • Route module for centralization of all application routes.
  • Logger module inclunding support for external log server.
    (In order to exemplify this project use Papertrail ).
  • Messages module for message strings centralization
  • Configuration to running in production using PM2.
  • Authentication support using JWT.
  • Base controller with CRUD operations for extension having the following features:
    • Query filter using query params
    • Pagination support
    • Soft delete support
    • Validation support
  • Database integration and Object Modeling Tool using mongoose.
  • CORS enabled.
  • Request validation using express-validator
  • Better messages for mongoose unique and required validations.
  • Migrations for easy database changes tracking and syncing across all develop team.
  • Included CI (Continuous Integration) with Travis CI.
  • Testing with Mocha and Chai.
  • Lint using Eslint.
  • Configuration for consistent coding styles across various editors and IDEs using EditorConfig.

Configuration

Create a .env file using .env.example as template. Setup the following variables:

  • NODE_ENV : Application execution enviroment
  • PORT : Server port
  • MONGO_URI : Connection URI for MongoDB
  • MIGRATE_dbConnectionUri : Connection URI for store migrate plugin metadata
  • JWT_SECRET : Secret for encrypt / decrypt jwt token
  • LOGGER_HOST : Host for external logging server
  • LOGGER_PORT : Port for external logging server

Scripts

This project comes with a some npm scripts. You can run them with npm run <script name> :

  • start : Run the application in development mode
  • watch : Run the application in development mode watching for file changes
  • lint : Run eslint plugin
  • fix : Run eslint plugin and try to automatically fix problems
  • migrate : Shortcut to run migration tool installed in node_modules folder
  • test : Set the enviroment variable and run mocha test cases

Test cases examples

The test cases examples can be found on test folder. There is an unit test for a generic AppError class, and integration tests for /auth and /user endpoints.

Support for PM2

This project comes with a basic PM2 configuration file called process.json, for PM2 use you could run the following command:

pm2 start process.json

Author

Keust Pablo Silvano ( e-mail, LinkedIn, Medium )

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published