Here are the setup instructions for node boilerplate project.
- Install NodeJs.
- Clone the project repository.
- Navigate to the project directory.
- Create
.envfile in the root folder and copy paste the content of.env.sample, and add necessary credentials. - Install the packages:
- NOTE: Recommended to use
yarninsted ofnpm - Yarn
- Install yarn globally
npm install --global yarnyarn install- OR
npm install- If you get an error while installing dependency with npm, run the following command to install dependency. (ignore all peerDependencies when installing)
npm install --legacy-peer-deps- Run the project in local:
npm run start- You're all set. Enjoy Happy coding! ☠️
- Install the Docker Desktop app.
- Clone the project repository.
- Navigate to the project directory.
- Create
.envfile in the root folder and copy paste the content of.env.sample, and add necessary credentials. - NOTE: If any changes are needed, you can update the steps accordingly in
Dockerfile. - NOTE: You can choose any name when building the image. I used
node-appfor this example. - Build the docker image.
docker build -t node-app .- Run the build image as docker container.
docker run -d -p 3010:3010 node-app- Verify the Application.
- All set! enjoy. ✌🏻
🎯 The boilerplate includes the following Core Backend Features and Development Utilities and Tools setup.
- Database: MongoDB, SQL(Sequelize)
- Middleware & Security: CORS, JWT, Roles & Permissions, Cookies
- Error Handling: Signal & Uncaught Error Exception, NodeJS Error Exception, Global Error
- APIs & Communication: REST APIs, Socket, Swagger Docs
- Deployment & Infrastructure: Docker
- Development Utilities: Nodemon, Babel, Husky
- Code Quality Tools: ESLint, Prettier
- Security Tools: Helmet, Rate Limiter, Express Basic Auth
- Logging and Monitoring Tools: Morgan, Winston
- Prettier
- Prettier is a tool that automatically formats your code to ensure a consistent style across your project.
- To check style issues via Prettier, use the following command.
npm run format:check- Run the following command to fix style issues.
npm run format:write- ESLint
- ESLint is a tool for identifying and fixing problems in JavaScript code. It helps maintain code quality by enforcing coding standards and detecting errors.
- Use the following command to identify all problems in files and print them in the terminal.
npm run lint- Husky
- Husky is a tool that enables Git hooks, allowing you to run scripts at various points in your Git workflow. It is commonly used to automate tasks such as running linters, formatters, and tests before commits or pushes, ensuring code quality and consistency across a team.
- NOTE: Before committing, automatically format files using Prettier and check for warnings and errors using ESLint. If both Prettier and ESLint pass without issues, allow the commit to proceed. Otherwise, reject the commit request. This ensures consistent formatting and maintains code quality standards before changes are finalized in the repository.
- Currently, we use the two husky hooks shown below.
pre-commitandcommit-msg
- Winston
- Winston is a flexible logging library for Node.js. It supports multiple logging levels, various output destinations, and custom formatting.
- i18n is a lightweight internationalization library for Node.js. It supports multiple locales, automatic language detection, customizable translation functions, and integrates easily as middleware in Express apps.
- Swagger docs available at the following URL.
- Swagger
- Here, How to use Swagger docs as Postman APIs
- Also we have the option to serve generated documentation content from Swagger for use in Postman APIs.
- Swagger Docs
- Use the provided URL to get the Swagger JSON content and copy it.
- Open the Postman app.
- Click the import button, paste the copied content, and click import.
- Now will see a collection with all APIs and their sample examples (NOTE: it will automatically set the environment variables for all APIs).
- You're all set. Enjoy!
- Fullstack Team ⚔️