This project is built using TypeScript, Express, and MongoDB.
The project files and directories are organized as follows:
/root
|-- node_modules/
| |-- (all modules installed by npm)
|
|-- public/
|
|-- src/
| |-- route/
| |-- middleware/
| |-- model/
| |-- service/
| |-- swagger/
| |-- type/
| |-- util/
|
|-- .env (environment variables)
|-- app.js (main application file)
|-- package.json
To run the project to dev, execute the following commands in the terminal:
-
Adding Environment Variables:
1-1. Duplicate
.env.example
and rename to.env
file1-2. Define Variables: Add variables on new lines in the format
KEY=VALUE
, for example:MONGODB_URL=mongodb://username:password@localhost:27017/database PORT=8000 NODE_ENV=development
-
(Optional) If you don't have MongoDB, you can use Docker to add it:
docker-compose -f docker-compose.dev.yml up // modify the .env MONGODB_URL=mongodb://root:example@localhost:27017/?authSource=admin
-
Install Dependencies:
yarn install
-
Start the Server:
yarn dev
Make sure your MongoDB service is up and running before starting the app, especially if it is being run locally.
Use Swagger for API documentation, check on schemaGenerator.js
for more detailed scripts.
- Generate Schemas
Please ensure keeping all the types in src/type
folder to build the schemas inside src/swagger/build
.
# Autogenerate swagger-output.json
yarn swagger
- Add Swagger Comments
Use swagger 2.0 features, check on document for more details.