This is a Middleware for building scalable and robust REST APIs using Node.js & TypeScript.
You need to install MongoDB on your local machine or use database as service.
-
TypeScript as Language
-
Framework: Express.js
-
ODM: Mongoose
-
Authentication & Authorization with JSON Web Tokens
-
Easy configuration of environment variables thanks to dotenv
-
EditorConfig for maintain consistent coding style
-
Morgan for logging request
-
Using the last ES6 / ES7 features as
async-await
-
Versioned routes for better scalability
-
install the dependencies using
npm install
ornpm i
-
copy the file
.env.local
to.env
-
Start the app using
npm start
-
After that, go to:
http://localhost:3000/
├── src
│ ├── apiV1
│ │ ├── auth
│ │ │ ├── auth.controller.ts
│ │ │ └── auth.route.ts
│ │ ├── clients
│ │ │ ├── client.controller.ts
│ │ │ ├── client.model.ts
| | | ├── client.service.ts
│ │ │ └── client.route.ts
│ │ └── index.ts
│ ├── config
│ │ ├── config.ts
│ │ └── db.ts
│ ├── helpers
│ │ ├── errorHandler.ts
│ │ └── verifyToken.ts
│ ├── .env.dev
| ├── .env.local
│ ├── App.ts
│ └── index.ts
├── .editorconfig
├── .gitignore
├── package.json
├── README.md
├── tsconfig.json
└── tslint.json
Method | Resource | Description |
---|---|---|
POST |
/clients/register |
Create a new client in the DB. You need to specify in the body the following attributes: name, client_id & client_secret. |
POST |
/authenticate |
Sign in with the client_id & client_secret. If it's successful, then generates a token |
You need to specify the token in the header with the following format: Authorization: Bearer your-token in Below Api's. |
start
- To run the app without transpile to ES6clean
- Remove dist, node_modules, coverage folders,lint
- Lint your TS code,build
- Transpile TypeScript to ES6,build-start
- Run the transpiled app,prod
- Build & run the transpiled app