You don't need to start your backend project from scratch anymore! This is a usefull, structured and supported with helpful examples, A backend template made mainly with four technologies: Express, Sequelize, Jest and Node server.
To be able to use this template, you need these technologies to be installed on your machine:
- NodeJS
- NPM Also, you need to have any SQL database URL (this project has been tested with PostgreSQL-v12 database).
This project has been created using these technologies:
- NodeJS
- Express
- Typescript
- Sequelize
- Hapi/Boom
- Jest
- ESLint
- Husky
Follow these steps respectively:
At first, you need to clone this template on your local machine, it would be better for you to fork this repo to your account. Specially if you want to make changes on the template and use your version later (then clone your forked repo), otherwise, clone my repo by running this command on your terminal:
git clone https://github.com/mhmdtshref/typescript-express-sequelize-template.git
You need to add environment variables to be able to connect to server port, host and database server. There's an example of env file in environment/.env.example. You should create a new file for each development mode, for example, for local mode, create a file with the name .env.local, then copy the example file content, and replace the variables values with yours.
Now, you need to install packages of package.json and package-lock.json files, just run this command on the root directory: environments/.env.example
Warning: By running this the up comming command, you'll create the user example table to the database.
Just run the npm script command:
npm run serve:[ENVIRONMENT_NAME]
The template is supporting four environments, you can modify them from pakcage.json > scripts
npm install.For example, run the template npm run serve:local, to run the app using local environment mode.
- Full API call example (so you can track it and know how API call life cycle work).
- Using Typescript language.
- Setup testing evironment using Jest tests with coverage reporting.
- Separated files for relations/associations between sequelize models.
- Database models validations.
- Using MVC pattern.
- eslint linting and fixing scripts.
- Auto-fixing for linting errors before committing changes.
- Supporting Multiple environments.
- One place to handle errors.
- Error handling using Hapi/Boom module (consistant & structured errors).
Mohamed Sharif |
|---|
This project is licensed under the MIT License - see the LICENSE file for details