A boilerplate for Express backend server in TypeScript.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
You need node@^12
and npm@^6
installed on your system.
If you want to use local MongoDB then you also need to MongoDB Server installed on your system. See these instructions.
A step by step series of examples that tell you how to get a development environment running.
Install all project dependency with npm
:
npm install
Then you need to create a .env
file with some required variables:
PORT=8000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/express
The default value of PORT
is set to 8000.
Now, you can start the application with the predefined scripts:
npm run dev
# OR
npm run start
The unit tests can also be run from a predefined script:
npm run test
The project uses husky
for git
hooks.
There are pre-commit hooks to run eslint
and prettier
on staged files.
There is a pre-push hook that runs the unit tests.
The configuration for this is present inside the package.json
file.
While deploying the application, set the NODE_ENV
variable in the .env
file to production
.
Note: If you want to use SSL for your server, you need to set SSL_KEY_FILE
and SSL_CERT_FILE
variables in the
.env
file. These variables should contain paths to the SSL key and certificate files.
The application can simply be deployed with the express server, or you can create a Docker image for deployment.
There is a Dockerfile
present in this project which can be used to create images that can be deployed in production.
To build a Docker image, run:
docker build . -t <tag>
To run this Docker image, run:
docker run -p 8000:8000 -d --env-file .env <tag>
- NodeJS - The JavaScript runtime.
- Express - The web framework.
- TypeScript - The language used.
- MongoDB - Database provider.
- Surya Kant Bansal - Initial work - skb1129
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Inspiration from TypeScript-Node-Starter.