hagopj13/node-express-boilerplate is a Developer Tools project on GitHub, written primarily in JavaScript. It has 7.7k stars. A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
A boilerplate/starter project for quickly building RESTful APIs using Node.js, Express, and Mongoose.
By running a single command, you will get a production-ready Node.js app installed and fully configured on your machine. The app comes with many built-in features, such as authentication using JWT, request validation, unit and integration tests, continuous integration, docker support, API documentation, pagination, etc. For more details, check the features list below.
Quick Start
To create a project, simply run:
npx create-nodejs-express-app <project-name>
Or
npm init nodejs-express-app <project-name>
Manual Installation
If you would still prefer to do the installation manually, follow these steps:
Clone the repo:
git clone --depth 1 https://github.com/hagopj13/node-express-boilerplate.git
cd node-express-boilerplate
npx rimraf ./.git
Install the dependencies:
yarn install
Set the environment variables:
cp .env.example .env
# open .env and modify the environment variables (if needed)
Table of Contents
Features
Commands
Environment Variables
Project Structure
API Documentation
Error Handling
Validation
Authentication
Authorization
Logging
Custom Mongoose Plugins
Linting
Contributing
Features
NoSQL database: MongoDB object data modeling using Mongoose
API documentation: with swagger-jsdoc and swagger-ui-express
Process management: advanced production process management using PM2
Dependency management: with Yarn
Environment variables: using dotenv and cross-env
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
Commands
Running locally:
yarn dev
Running in production:
yarn start
Testing:
# run all tests
yarn test
# run all tests in watch mode
yarn test:watch
# run test coverage
yarn coverage
Docker:
# run docker container in development mode
yarn docker:dev
# run docker container in production mode
yarn docker:prod
# run all tests in a docker container
yarn docker:test
The environment variables can be found and modified in the .env file. They come with these default values:
# Port number
PORT=3000
# URL of the Mongo DB
MONGODB_URL=mongodb://127.0.0.1:27017/node-boilerplate
# JWT
# JWT secret key
JWT_SECRET=thisisasamplesecret
# Number of minutes after which an access token expires
JWT_ACCESS_EXPIRATION_MINUTES=30
# Number of days after which a refresh token expires
JWT_REFRESH_EXPIRATION_DAYS=30
# SMTP configuration options for the email service
# For testing, you can use a fake SMTP service like Ethereal: https://ethereal.email/create
SMTP_HOST=email-server
SMTP_PORT=587
SMTP_USERNAME=email-server-username
SMTP_PASSWORD=email-server-password
[email protected]
Project Structure
src\
|--config\ # Environment variables and configuration related things
|--controllers\ # Route controllers (controller layer)
|--docs\ # Swagger files
|--middlewares\ # Custom express middlewares
|--models\ # Mongoose models (data layer)
|--routes\ # Routes
|--services\ # Business logic (service layer)
|--utils\ # Utility classes and functions
|--validations\ # Request data validation schemas
|--app.js # Express app
|--index.js # App entry point
API Documentation
To view the list of available APIs and their specifications, run the server and go to http://localhost:3000/v1/docs in your browser. This documentation page is automatically generated using the swagger definitions written as comments in the route files.
API Endpoints
List of available routes:
Auth routes: POST /v1/auth/register - register POST /v1/auth/login - login POST /v1/auth/refresh-tokens - refresh auth tokens POST /v1/auth/forgot-password - send reset password email POST /v1/auth/reset-password - reset password POST /v1/auth/send-verification-email - send verification email POST /v1/auth/verify-email - verify email
User routes: POST /v1/users - create a user GET /v1/users - get all users GET /v1/users/:userId - get user PATCH /v1/users/:userId - update user DELETE /v1/users/:userId - delete user
Error Handling
The app has a centralized error handling mechanism.
Controllers should try to catch the errors and forward them to the error handling middleware (by calling next(error)). For convenience, you can also wrap the controller inside the catchAsync utility wrapper, which forwards the error.
const catchAsync = require('../utils/catchAsync');
const controller = catchAsync(async (req, res) => {
// this error will be forwarded to the error handling middleware
throw new Error('Something wrong happened');
});
The error handling middleware sends an error response, which has the following format:
{
"code": 404,
"message": "Not found"
}
When running in development mode, the error response also contains the error stack.
The app has a utility ApiError class to which you can attach a response code and a message, and then throw it from anywhere (catchAsync will catch it).
For example, if you are trying to get a user from the DB who is not found, and you want to send a 404 error, the code should look something like:
const httpStatus = require('http-status');
const ApiError = require('../utils/ApiError');
const User = require('../models/User');
const getUser = async (userId) => {
const user = await User.findById(userId);
if (!user) {
throw new ApiError(httpStatus.NOT_FOUND, 'User not found');
}
};
Validation
Request data is validated using Joi. Check the documentation for more details on how to write Joi validation schemas.
The validation schemas are defined in the src/validations directory and are used in the routes by providing them as parameters to the validate middleware.
These routes require a valid JWT access token in the Authorization request header using the Bearer schema. If the request does not contain a valid access token, an Unauthorized (401) error is thrown.
Generating Access Tokens:
An access token can be generated by making a successful call to the register (POST /v1/auth/register) or login (POST /v1/auth/login) endpoints. The response of these endpoints also contains refresh tokens (explained below).
An access token is valid for 30 minutes. You can modify this expiration time by changing the JWT_ACCESS_EXPIRATION_MINUTES environment variable in the .env file.
Refreshing Access Tokens:
After the access token expires, a new access token can be generated, by making a call to the refresh token endpoint (POST /v1/auth/refresh-tokens) and sending along a valid refresh token in the request body. This call returns a new access token and a new refresh token.
A refresh token is valid for 30 days. You can modify this expiration time by changing the JWT_REFRESH_EXPIRATION_DAYS environment variable in the .env file.
Authorization
The auth middleware can also be used to require certain rights/permissions to access a route.
In development mode, log messages of all severity levels will be printed to the console.
In production mode, only info, warn, and error logs will be printed to the console.
It is up to the server (or process manager) to actually read them from the console and store them in log files.
This app uses pm2 in production mode, which is already configured to store the logs in log files.
Note: API request information (request url, response code, timestamp, etc.) are also automatically logged (using morgan).
Custom Mongoose Plugins
The app also contains 2 custom mongoose plugins that you can attach to any mongoose model schema. You can find the plugins in src/models/plugins.
In this app, ESLint is configured to follow the Airbnb JavaScript style guide with some modifications. It also extends eslint-config-prettier to turn off all rules that are unnecessary or might conflict with Prettier.
To modify the ESLint configuration, update the .eslintrc.json file. To modify the Prettier configuration, update the .prettierrc.json file.
To prevent a certain file or directory from being linted, add it to .eslintignore and .prettierignore.
To maintain a consistent coding style across different IDEs, the project contains .editorconfig
Contributing
Contributions are more than welcome! Please check out the contributing guide.
Does hagopj13/node-express-boilerplate have a project website?
No homepage URL was recorded for hagopj13/node-express-boilerplate in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How active is development on hagopj13/node-express-boilerplate?
The most recent commit recorded on hagopj13/node-express-boilerplate was 2.4 years ago, based on the GitHub push timestamp. The repository has 2.3k forks — one of the better signals of community interest.
Is hagopj13/node-express-boilerplate open source?
Yes — hagopj13/node-express-boilerplate ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/hagopj13/node-express-boilerplate.
What license does hagopj13/node-express-boilerplate use?
hagopj13/node-express-boilerplate is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is hagopj13/node-express-boilerplate associated with?
Where do I read more about hagopj13/node-express-boilerplate?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/hagopj13/node-express-boilerplate is the definitive source.
Read full README in the tab above.
Curious whether node-express-boilerplate is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about node-express-boilerplate.