This is a boilerplate for building scalable and robust REST APIs using Node.js & TypeScript.
You need to install MongoDB either on your local machine or using a cloud service as mLab.
-
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
-
Rename the file
.env.example
to.env
, then you need to configure the fileconfig.ts
located insrc/config
-
Start the app using
npm run dev
-
After that, go to:
http://localhost:3000/v1/users
├── src
│ ├── apiV1
│ │ ├── auth
│ │ │ ├── auth.controller.ts
│ │ │ └── auth.route.ts
│ │ ├── users
│ │ │ ├── user.controller.ts
│ │ │ ├── user.controller.ts
│ │ │ └── user.route.ts
│ │ └── index.ts
│ ├── config
│ │ ├── config.ts
│ │ └── db.ts
│ ├── helpers
│ │ ├── errorHandler.ts
│ │ └── verifyToken.ts
│ ├── .env.example
│ ├── App.ts
│ └── index.ts
├── .editorconfig
├── .gitignore
├── package.json
├── README.md
├── tsconfig.json
└── tslint.json
Method | Resource | Description |
---|---|---|
POST |
/register |
Create a new user in the DB. You need to specify in the body the following attributes: name, lastname, email & password. |
POST |
/authenticate |
Sign in with the email & password. If it's successful, then generates a token |
GET |
/users |
Returns the collection of users present in the DB. |
GET |
/users/:id |
It returns the specified id user. You need to specify the token in the header with the following format: Authorization: Bearer your-token |
PUT |
/users/:id |
Updates an already created user in the DB |
DELETE |
/users/:id |
Deletes a user from the DB |
build
- Transpile TypeScript to ES6,lint
- Lint your TS code,dev
- To run the app without transpile to ES6,clean
- Remove dist, node_modules, coverage folders,start
- Run the transpiled appprod
- Build & run the transpiled app
MIT © Michael Méndez