This template should help get you started developing in Node with Express and TypeScript.
# copy env file
cp .env.development .env
# run postgres container with docker-compose
docker-compose -f docker-compose.dev.yml up --build
# install dependencies
npm install
# run server
npm start
# run migrations and seeders
npm run migration
npm run seed
# sign in
curl --request POST \
--url http://localhost:5001/api/signin \
--header 'Content-Type: application/json' \
--data '{ "email": "admin@mail.com", "password": "123456" }'
# psql basic command
# open connection
psql -U root -d express_db -h localhost
# list all databases
\l
# connect to database
\c express_db
# list all tables
\dt
# table detail
\d "Users"
node
version 16.14.2 the last LTSnpm
version 8.5.0
- VS Code
- VS Code Extension - Prettier: This is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules.
- VS Code Extension - PlantUML: This is a useful tool for creating and previewing PlantUML diagrams.
These extensions are configured to be recommended to the user in the first use. You can see the recommended extensions running Show Recommended Extensions
from VS Code's command palette,
- Express v4.17.1
- Typescript v4.5.4
- Sequelize v6.6.5 - with decorators @sequelize-typescript + Postgres
- Formatter with ESLint rules + Prettier
- Test with Jest
- API documentation with swagger
-
ESLint rules is a tool for identifying and reporting on pattern found in the code, with the goal of making code more consistent and avoid bugs. Here are the rules used for this project:
- eslint - eslint:recommended.
- eslint-typescript - plugin:@typescript-eslint/recommended.
-
- pre-commit - runs lint-staged check
- commit-msg - runs commitlint check
- pre-push - runs test script
npm run test
-
Prettier - is an opinionated code formatter.
- Auto formatter code on save using eslint-config-prettier
Command | Description |
---|---|
npm run serve |
Builds and runs the application |
npm start |
Starts the application in development mode using nodemon and ts-node to do hot reloading. |
npm run build |
Builds the application at build , cleaning the folder first |
npm run lint |
Runs lint command. |
npm run test |
Runs the jest tests once. |
npm run test:coverage |
Runs the jest coverage once. |
npm run test:dev |
Runs the jest tests and watches for any change. |
npm run migrate |
Runs the sequelize-cli command to run migrations. |
npm run migrate:undo |
Runs the sequelize-cli command to undo migrations. |
npm run seed |
Runs the sequelize-cli command to run seeders. |
npm run seed:undo |
Runs the sequelize-cli command to undo seeders. |
Variable | Description |
---|---|
ENV |
Environment name. ej. development , test , production |
APP_NAME |
Application name |
APP_PORT |
Application port number |
LOG_LEVEL |
Log level for logging services |
DB_USERNAME |
Username for database configuration |
DB_PASSWORD |
Password for database configuration |
DB_DATABASE |
Database for database configuration |
DB_HOST |
Host for database configuration |
DB_PORT |
Port for database configuration |
SECRET_KEY_TOKEN |
Secret key for access token generation |
SECRET_KEY_PASSWORD |
Secret key for encrypt password |
ADMIN_EMAIL |
Email for admin user |
ADMIN_USERNAME |
Username for admin user |
ADMIN_PASSWORD |
Password for admin user |