Skip to content

kaushal-aubie/node-boilerplate

Repository files navigation

react boilerplate banner


Start a new application in seconds!
A highly scalable, configurable, performant with best practices

Table of contents

Quick-start

  1. Make sure that you have Node.js v12.x.x and npm v5 or above installed.
  2. Clone this repo using git clone https://github.com/kaushal-aubie/node-boilerplate.git <YOUR_PROJECT_NAME>
  3. Move to the appropriate directory: cd <YOUR_PROJECT_NAME>.
  4. Run npm run install in order to install dependencies.
    At this point you can run npm run dev to see the app running at http://localhost:5000.
  5. Got to http://localhost:5000/ping to receive a pong from the server.

Now you're ready to rumble!

Features

TypeScript
The best way to write modern applications. Code is easier to understand. It is now way more difficult to write invalid code as was the case in dynamically typed languages
Static code analysis
Focus on writing code, not formatting! Code formatter and linter keeps the code clean which makes work and communication with other developers more effective.
Next generation JavaScript
Use template strings, object destructuring, arrow functions,ES2017 latest features like Async/Await and more
Ready for any Environment
It is ready to work with any environment such as Development, Production and staging and all can have their different `.env` files
Path alias
Create a path alias in `tsconfig.json` and it will allow to find a file or resource located in a different directory or folder from the place where the shortcut is located.
Docker Support
Comes with a Dockerfile and docker compose file
Compression
Gzip compression with compression
Git Hooks
Awesome Command line Git Commitization integrated with husky
Logging
Jet Logger For great logging and morgan added for api request logging
Validation
Request data validation using JOI
Security
set security HTTP headers using helmet
CORS
Included CORS
Email helper
Email helper ready just to import and use
File Upload helper
File Upload helper ready to just import and use
Response Structure
Pre-defined response structures with proper status codes.

Configuration

  • Docker Compose File docker/docker-compose.yml
  • DockerFile docker/Dockerfile
  • Prettier config /.prettierc.
  • Typescript config /tsconfig.json.
  • ESLint config /.eslintrc.js.
  • Commitlint config /commitlint.config.js.
  • Husky config /.husky.
  • VScode config /.vscode.

Scripts

  • npm run docker:up - Starts the Docker app.
  • npm run docker:stop - Stops the Docker app.
  • npm run docker:down - Stop the Docker Compose Process.
  • npm run docker:remove-dangling - Remove/Delete Dangling Images.
  • npm run docker:compose - Start the App.
  • npm run docker:compose:d - Start the App in detached mode.
  • npm run docker:logs - Start Logs in Docker for app.
  • npm run docker:restart - Restart the Docker app.
  • npm run docker:exec - Open path to the repo inside Docker as bash
  • npm run docker:logs:follow - Start Logs in Docker for app.
  • npm run docker:seed - To add dummy data in Database in development mode inside docker app.
  • npm run start - To run app in production mode.
  • npm run dev - To run app in development mode.
  • npm run kill-process - To kill process at running port.
  • npm run build - To build the code.
  • npm run format - To prettify code.
  • npm run check-lint - To check lint errors.
  • npm run check-types - To check typescript errors.
  • npm run check-all - To check lint,typescript and build errors.
  • npm run commit - To commit your changes.
  • npm run seed - To add dummy data in Database in development mode.
  • npm run seed:prod - To add dummy data in Database in production mode.

Git Commitization

Configuring the gitmoji only once

> npx gitmoji -g
> ? Enable automatic "git add ." (y/N) N
> ? Select how emojis should be used in commits (Use arrow keys)
	  :smile:
	❯ 😄
> ? Enable signed commits (y/N) N
> ? Enable scope prompt (Y/n) Y

Commit workflow

npm run commit

Step 1: Choose a gitmoji from the list

? Choose a gitmoji: (Use arrow keys or type to search)
> 🎨  - Improve structure / format of the code.
  ⚡️  - Improve performance.
  🔥  - Remove code or files.
  🐛  - Fix a bug.
  🚑️  - Critical hotfix.
  ✨  - Introduce new features.
  📝  - Add or update documentation.
(Move up and down to reveal more choices)

Step 2: Add a scope, title and message

? Choose a gitmoji: 🎨  - Improve structure / format of the code.
? Enter the scope of current changes: hello
? Enter the commit title [5/48]: title
? Enter the commit message: message

Now it will run lint, types and build scripts if everything is ok, changes will be committed

Git commit message format will be :- git commit -m ":gitmoji: title" -m "message"

Project structure

├───.husky                  # Husky hooks
│───.vscode                 # VS Code Settings
│─── docker                 # Docker configs
│─── dist                   # Production Build
│─── env                    # Environment files
│─── src\
│    |--config\             # Environment variables and configuration related things
│    |--controllers\        # Route controllers (controller layer)
│    |--db\                 # Database Configuration
│    |--middlewares\        # Custom express middlewares
│    |--interfaces\         # All Shared Global Interfaces
│    |--libs\               # External Libs Config
│    |--models\             # Sequelize models (data layer)
│    |--routes\             # Routes
│    |--services\           # Business logic (service layer)
│    |--utils\              # Utility classes and functions
│    |--validations\        # Request data validation schemas
│    |--response_builder\   # Generic Response Builder logic
│    |--seeds\              # Dummy Data Generation Files
│    |--types\              # Global Typescript Types Definitions
│    |--app.ts              # Express app
│    |--server.ts           # App entry point
│
├── .gitignore              # git ignore
├── .dockerignore           # docker ignore
├── .prettierrc             # Prettier Config
├── .commitlint.config.js   # Commitlint Configuration
├── nodemon.json            # nodemon config
├── package.json            # blue print of app
├── package-lock.json       # package lock file for bindings of packages
├── private.pem             # pem file for JWT
├── README.md               # Readme File
└── tsconfig.json           # Type Script Configuration File

Important Packages

Server/Framework

  • express - Fast, unopinionated, minimalist web framework

Middleware

  • compression - Node.js compression middleware
  • cookie-parser - Parse HTTP request cookies
  • cors - Node.js CORS middleware
  • morgan - HTTP request logger middleware for node.js
  • helmet - Help secure Express/Connect apps with various HTTP headers

Database

  • pg - PostgreSQL client - pure javascript & libpq with the same API
  • pg-hstore - A module for serializing and deserializing JSON data into hstore format
  • sequelize - Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Amazon Redshift and Snowflake’s Data Cloud. It features solid transaction support, relations, eager and lazy loading, read replication and more.

Eslint

Others

  • command-line-args - A mature, feature-complete library to parse command-line options.
  • bcrypt - A bcrypt(encryption) library for NodeJS.
  • dotenv - Loads environment variables from .env file
  • jet-logger - A super quick, easy to setup logging tool for NodeJS/TypeScript.
  • joi - Object schema validation
  • jsonwebtoken - JSON Web Token implementation (symmetric and asymmetric)

Authors

Kaushal Shah
Kaushal Shah

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors