Backend meal ordering application written with Node.js, Express.js and Typescript
Install the dependencies:
yarn install
Set the environment variables:
cp .env.example .env
- ES9: latest ECMAScript features
- Static Typing: TypeScript static typing using typescript
- Hot Reloading: Concurrently Hot realoding with concurrently
- NoSQL database: MongoDB object data modeling using Mongoose
- Authentication and authorization: using passport
- Validation: request data validation using Joi
- Logging: using winston and morgan
- Testing: unit and integration tests using Jest
- Error handling: centralized error handling mechanism
- API documentation: with swagger-jsdoc and swagger-ui-express
- Process management: advanced production process management using PM2
- Dependency management: with Yarn
- Environment variables: using dotenv and cross-env
- Security: set security HTTP headers using helmet
- Santizing: sanitize request data against xss and query injection
- CORS: Cross-Origin Resource-Sharing enabled using cors
- Compression: gzip compression with compression
- CI: continuous integration with GitHub CI
- Docker support
- Code coverage: using codecov
- Code quality: with Codacy
- Git hooks: with husky and lint-staged
- Linting: with ESLint and Prettier
- Editor config: consistent editor configuration using EditorConfig
- Changelog Generation: with Standard Version
- Structured Commit Messages: with Commitizen
- Commit Linting: with CommitLint
Running locally:
yarn dev
Running in production:
yarn start
Compiling to JS from TS
yarn compile
Compiling to JS from TS in watch mode
yarn compile:watch
Commiting changes
yarn commit
Testing:
# run all tests
yarn test
# run TypeScript tests
yarn test:ts
# run JS tests
yarn test:js
# run all tests in watch mode
yarn test:watch
# run test coverage
yarn coverage
Docker:
# run docker container in development mode
yarn docker:dev
# run docker container in production mode
yarn docker:prod
# run all tests in a docker container
yarn docker:test
Linting:
# run ESLint
yarn lint
# fix ESLint errors
yarn lint:fix
# run prettier
yarn prettier
# fix prettier errors
yarn prettier:fix
Run yarn dev
so you can compile Typescript(.ts) files in watch mode
yarn dev
Add your changes to TypeScript(.ts) files which are in the src folder. The files will be automatically compiled to JS if you are in watch mode.
Add tests for the new feature
Run yarn test:ts
to make sure all Typescript tests pass.
yarn test:ts
The environment variables example can be found and modified in the .env.example
file. They come with these default values:
# Port number
PORT=3000
# URL of the Mongo DB
MONGODB_URL=mongodb://127.0.0.1:27017/Park254_Backend
# JWT
# JWT secret key
JWT_SECRET=thisisasamplesecret
# Number of minutes after which an access token expires
JWT_ACCESS_EXPIRATION_MINUTES=30
# Number of days after which a refresh token expires
JWT_REFRESH_EXPIRATION_DAYS=30
# SMTP configuration options for the email service
# For testing, you can use a fake SMTP service like Ethereal: https://ethereal.email/create
SMTP_HOST=email-server
SMTP_PORT=587
SMTP_USERNAME=email-server-username
SMTP_PASSWORD=email-server-password
[email protected]
# URL of client application
CLIENT_URL=http://localhost:5000
.
├── src # Source files
│ ├── app.ts # Express App
│ ├── config # Environment variables and other configurations
│ ├── custom.d.ts # File for extending types from node modules
│ ├── declaration.d.ts # File for declaring modules without types
│ ├── index.ts # App entry file
│ ├── modules # Modules such as models, controllers, services
│ └── routes # Routes
├── TODO.md # TODO List
├── package.json
└── README.md
To view the list of available APIs and their specifications, run the server and go to http://localhost:3000/v1/docs
in your browser. This documentation page is automatically generated using the swagger definitions written as comments in the route files.
List of available routes:
Auth routes:
POST /v1/auth/register
- register
POST /v1/auth/login
- login
POST /v1/auth/refresh-tokens
- refresh auth tokens
POST /v1/auth/forgot-password
- send reset password email
POST /v1/auth/reset-password
- reset password
User routes:
POST /v1/users
- create a user
GET /v1/users
- get all users
GET /v1/users/:userId
- get user
PATCH /v1/users/:userId
- update user
DELETE /v1/users/:userId
- delete user
Meal routes:
POST /v1/meals
- create a meal
GET /v1/meals
- get all meal
GET /v1/meals/:mealId
- get meal
PATCH /v1/meals/:mealId
- update meal
DELETE /v1/meals/:mealId
- delete meal
Menu routes:
POST /v1/menu
- create a menu
GET /v1/menu
- get all menu
GET /v1/menu/:menuId
- get menu
PATCH /v1/menu/:menuId
- update menu
DELETE /v1/menu/:menuId
- delete menu
Order routes:
POST /v1/order
- create a order
GET /v1/order
- get all order
GET /v1/order/:orderId
- get order
PATCH /v1/order/:orderId
- update order
DELETE /v1/order/:orderId
- delete order