This is a boilerplate project for building a Node.js application using Express.js. It provides a solid foundation with a structured directory layout, commonly used middlewares, microservice architecture, and some best practices for building scalable applications.
- Express.js: Fast, unopinionated, minimalist web framework for Node.js
- ESLint: Linting JavaScript code for consistency and avoiding errors
- Prettier: Code formatter for maintaining code style
- dotenv: Loads environment variables from a
.envfile - Morgan: HTTP request logger middleware for Node.js
- Helmet: Helps secure Express apps by setting various HTTP headers
- CORS: Cross-Origin Resource Sharing middleware
- JWT: Authentication Method with Json Web Token
- MongoDB: Database MongoDB for storing data
- Docker: Docker for containerized
- Clone the repository:
git clone git@github.com:aldo235/nodejs-boilerplate-express.git cd nodejs-boilerplate-express - Install dependencies:
npm install # or yarn install - Set up environment variables:
- Create a .env file in the root of the project.
- Add the following variables:
PORT= BASIC_AUTH_USERNAME= BASIC_AUTH_PASSWORD= JWT_SECRET= JWT_ISSUER=
- Run the application:
# DEV npm run start dev yarn start dev #PROD npm run start yarn start
- Build Docker:
docker build -t boilerplate:latest . - Set up environment variables:
- Create a .env file in the root of the project.
- Add the following variables:
PORT= BASIC_AUTH_USERNAME= BASIC_AUTH_PASSWORD= JWT_SECRET= JWT_ISSUER=
- Run Docker:
docker run --env-file __LOCATION_ENV__ --name boilerplate -d --publish 8080:8080 boilerplate:latest ``