The goal of this project is to create a REST API product database using the Express framework, written in Typescript, then containerized into a Docker container.
The plan is to do all of this while following best practices.
The technologies I will use to achieve this are:
- Node.js
- Express.js
- Docker
Database:
- MongoDB
Testing:
- Jest
- Postman
Git Hooks:
- Husky
- ESLint
- Lint-staged
The Postman Collection for testing this project is avaliable here
You need to set up your development environment before you can do anything.
Install Node.js and NPM
- on OSX use homebrew
brew install node - on Windows use chocolatey
choco install nodejs - on a Debian Linux distribution use apt
sudo apt install nodejs npm
make sure node is at least v16 with the following command
node -vIf you have any issues updating it try this link
Install yarn globally
npm install --global yarnThen install the node modules
yarn installInstall docker then start the mongodb container
docker compose up -dIf you don't have a config folder you'll have to add one inside the src folder using the following template. You need a default.ts, test.ts and if setting up for production, a production.ts file. You'll also need an RSA key, to set the saltWorkFactor and a google geocoding API key.
export default {
port: 3000,
dbUri: "mongodb://localhost:27017/rest-api",
saltWorkFactor:,
accessTokenTtl: '15m',
refreshTokenTtl: '1y',
publicKey: ``,
privateKey: ``,
apiKey: ""
}Run this command
yarn devThis starts a local server using
nodemon, which will watch for any file changes and will restart the server according to these changes. The server address will be displayed to you ashttp://localhost:3000.