Clone the repository
git clone <git repo URI>
Switch to the repo folder
cd <your Folder>
Install dependencies
npm install
Prettier is an opinionated code formatter.
ESLint, Find and fix problems in your JavaScript code
It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
-
CMD
+Shift
+P
(Mac Os) orCtrl
+Shift
+P
(Windows) -
Format Selection With
-
Configure Default Formatter...
-
Prettier - Code formatter
.
├── dist/ [the compiled output]
├── docs/ [openapi documentation]
├── src/ [the source code]/
│ ├── config/ [configuration files, including the env file variables]/
│ │ └── env.ts
│ ├── constants/ [constants]/
│ │ ├── common.constants.ts
│ │ └── HttpStatusCodes.ts
│ ├── database/ [database configuration (including sequelize instance and models initializations)]/
│ │ ├── sequelize/
│ │ │ ├── migrations/ [sequelize migrations]
│ │ │ ├── seeders/ [sequelize seeders]
│ │ │ └── sequelize-cli.js [sequelize cli configuration]
│ │ └── index.ts [database initialization]
│ ├── exceptions/ [custom exceptions]/
│ │ └── HttpException.ts
│ ├── interfaces/ [interfaces]/
│ │ ├── app/ [interfaces for the app and its business logic]
│ │ └── express/ [some app according custom interfaces for the framework]
│ ├── models/ [sequelize models]/
│ │ └── index.ts [exports all models which are then imported in the database/index.ts]
│ ├── server/
│ │ ├── controllers/ [controllers]
│ │ ├── helpers/ [app specific helpers]
│ │ ├── middlewares/ [middlewares]
│ │ ├── routes/ [routes]
│ │ ├── schemas/ [schemas (yup schemas for validations)]
│ │ ├── services/ [services]
│ │ └── server.ts [server initialization exports express App]
│ ├── tests/ [tests]/
│ │ ├── e2e/ [end to end tests]
│ │ └── -- other tests --
│ ├── utils/ [utils]/
│ │ └── logger.ts [logger]
│ └── main.ts [main bootstrap file]
├── .editorconfig
├── .env.example
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── jest.config.ts
├── nodemon.json
├── .nvmrc
├── package.json
├── package-lock.json
├── .prettierignore
└── .prettierrc
NODE_ENV='development' # development, production, test
# mysql config
DATABASE_HOST='127.0.0.1'
DATABASE_USER='root'
DATABASE_PASSWORD='root'
DATABASE_PORT=3306
DATABASE_SCHEMA='ts-express'
DATABASE_POOL_MAX=10
DATABASE_POOL_MIN=0
DATABASE_POOL_ACQUIRE=10000
DATABASE_POOL_IDLE=30000
#server config
PORT=3000
#jwt config
JWT_SECRET='MY_SERUPER_DUPER_SECURE_HARD_TO_GUESS_SECRET'
JWT_TOKEN_EXPIRE_TIME_IN_HOURS=576 #24 days
To pass an environment -->
NODE_ENV={your environment}
The app will pick corresponding .env file::
eg.:: if you run NODE_ENV=production npm start
then the production.env
file will be used by the app...
| NOTE:: look for casing when passing the node environment
The database server is --> MYSQL RECOMMENDED version v8.0 or higher
The orm that is use --> Sequelize V6
start
: starts the app with nodemonstart:prod
: runs the builded app in production modestart:dev
: start the app in development mode with nodemonclean
: removes the dist folderclean:all
: removes the dist folder and node_modulesbuild
: builds the app with swcbuild:tsc
: builds the app with tsc !!lint
: runs eslintlint:fix
: runs eslint with fixformat
: formats the code with prettierts:check
: checks the typescript code with tscdb:migrate
: runs the migrationsdb:migrate:undo
: undoes the last migrationdb:migrate:undo:all
: undoes all migrationsdb:migrate:status
: shows the migration statusdb:migration:generate
: generates a new migration with the given namedb:seed:generate
: generates a new seed with the given namedb:seed
: runs the seeddb:seed:all
: runs all seedstest
: runs all teststest:e2e
: runs the e2e tests excluding the tests in the e2e folder
The project is configured to run in a dev container. This means that you can run the project in a container without having to install any dependencies like database on your local machine.
- Docker
- System with at least 8GB of RAM
- 4 CPU cores
- 20GB of free disk space
- VSCode with the Remote - Containers extension installed
- Open the project in VSCode
- Press
F1
orCtrl+Shift+P
and selectRemote-Containers: Reopen in Container
This will start building the container and installing all dependencies. Once finished, you can start the server by running npm start:dev
in the terminal.