A simple boilerplate code for bootstrapping a NodeJS Express backend in Typescript.
- cors
- body-parser
- compress
- .env environment variables
- simple console logging for requests
- prettier, eslint and nodemon for rapid development
- ESLint
- Prettier
- DotENV
- Create a copy of
example.env
named.env
yarn install
yarn run dev
Start adding stuff
yarn start
- Starts the app. Needs to be builded firstyarn run build
- Builds the app (typescript compilation)yarn run dev
- Starts nodemon (Auto-restart on changes with auto-rebuild)
All of the env variables are handled within the env.ts
file. This file exports the env variable that includes all the environment variables imported. When you add a new environment variable, make sure to add it to the .env
file and to the example.env
file for sharing it with others. Remember to only put sensitive data on the .env
file and not on the example.env
one.
Just copy the hello-world.ts file and start working. Remember afterwards to add an app.use
statement on the app.ts
file.
If you want to add mongodb, install the necessary packages (mongodb, mongoose with their respective types) and proceed. For SQL, I suggest typeorm, with the respective driver (mysql, postgres etc).
You will also need to create a new database. The easiest way to achieve that is to create a docker instance. But you can always connect to an already existing mongodb (see mongodb atlas).
- Add a testing framework