This is a simple boilerplate with Express.js with a ready-to-use configuration for backend development. You can adjust it according to your requirements.
- ⚡ Express.js as the backend framework
- 📋 Swagger for API documentations
- 🛠 Typescript for strong type support
- 📄 Linting with ESlint and Prettier
Make sure you have installed the following tools:
- Node.js >= v18.x.x
- npm
-
Clone repository:
git clone https://github.com/pius706975/express-typescript-sequelize-boilerplate.git
-
Install the dependencies:
npm install
-
Create
.env.developmentto store the environment configuration:.env.development
-
Fill the
.env.developmentfile based on your requirements:PORT = port number NODE_ENV = env BASE_URL = base url DB_PORT = db port DB_USERNAME = db username DB_PASSWORD = db password DB_NAME = db name DB_HOST = host DB_DIALECT = dialect JWT_ACCESS_TOKEN_SECRET = JWT secret
Run the server in the development mode:
npm run devOr in the production mode
npm startRun the test:
- Test all function
npm run test - Test by selecting the file
npm run test path-to-your-test-file/file.test.ts
-
Linting and code formatting:
npm run lint # Linting check npm run lint:fix # Formatting code with prettier
-
Creating DB table:
npm run migration:generate --name "create-table-name"
Access swagger documentations: http://localhost:5000/api-docs
Swagger will automatically return the documentations based on route file annotation.
Let's have a look at this structure:
├── /node_modules
├── /src
│ ├── /config # Base configuration such as .env key and sequelize-cli configuration
│ ├── /database
│ │ ├── /migrations # DB migration files to migrate our DB tables
│ │ └── /models # DB model files that will be used in the development
│ ├── /docs # Swagger documentations
│ ├── /interfaces # Interfaces
│ ├── /logs # Access logs
│ ├── /middleware # App middlewares
│ ├── /modules # App modules
│ │ ├── /auth #
│ │ ├── /user # These module directories will store repo, service, controller, routes, and validator files.
│ │ └── /etc #
│ ├── /routes # Main route file that store all of the module routes
│ ├── /types # typescript support
│ ├── /utils # Utils
│ └── server.js # Entry point of the app
├── /tests # Unit test main folder
│ ├── /middleware # Middleware tests
│ ├── /modules # Modules tests
├── .env.development # Development environment variables
├── package.json # Dependencies and scripts
└── README.md # Project documentation
POST a request to /api/example:
curl --request POST --url http://localhost:5000/api/auth/signupResponse:
{
"message": "Successfully signed up"
}- Pius Restiantoro - GitHub# sales