Skip to content

najienka/RESTful-API-using-Node.js-Express-Mongoose-TypeScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTful API using Node.js, Express, Mongoose & TypeScript

technologies

This is a boilerplate for building scalable and robust REST APIs using Node.js & TypeScript.

Table of Contents

Prerequisites

You need to install MongoDB either on your local machine or using a cloud service as mLab.

Features

Getting Started

Installation

  1. install the dependencies using npm install or npm i

  2. Rename the file .env.example to .env, then you need to configure the file config.ts located in src/config

  3. Start the app using npm run dev

  4. After that, go to: http://localhost:3000/v1/users

Directory Structure

├── 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

Available routes

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

Available scripts

  • 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 app
  • prod - Build & run the transpiled app

License

MIT © Auto Inspector