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
EditorConfigfor maintain consistent coding style
Morganfor logging request
Using the last ES6 / ES7 features as async-await
Versioned routes for better scalability
install the dependencies using npm install
or npm i
Rename the file .env.example
to .env
, then you need to configure the file config.ts
located in src/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 appMIT © Michael Méndez
搭建Node TS开发环境 项目结构 npm init -y npm i typescript ts-node-dev tslint @types/node -D npm i sequelize-typescript@0.6.11 npm i sequelize@6.3.3 启动脚本 "scripts": { "start": "ts-node-dev ./src/index.ts -P ts
本文利用nodejs+restify 开发rest api,非express 等rest服务。去除了多余的模板内容。 操作步骤: 1.下载依赖: cnpm install restify restify-plugins restify-errors --save 复制代码 2.hello-world: /** * Module Dependencies */ const config = re
//npm install node-rest-client --save-dev var Client = require('node-rest-client').Client function locate() { var client = new Client() var args = { data: { input: "hello" },
app.js 'use strict'; console.log('Hello world'); const Koa = require('koa'); const bodyParser = require('koa-bodyparser'); const app = new Koa(); const controller = require('./controller'); // parse
Building RESTful Web APIs with Node.js, Express, MongoDB and TypeScript This is a simple API that saves contact information of people. There are two versions of this project. V1.0.0: you can run the s
Clean Node API Link para o curso completo Essa API faz parte do treinamento do professor Rodrigo Manguinho (Mango) na Udemy. O objetivo do treinamento é mostrar como criar uma API com uma arquitetura
Node - Koa - Typescript Project The main purpose of this repository is to build a good project setup and workflow for writing a Node api rest in TypeScript using KOA and an SQL DB. Koa is a new web fr
Node.js API com Typescript Código do curso �� DO ZERO A PRODUÇÃO: APRENDA A CONSTRUIR UMA API NODE.JS COM TYPESCRIPT Durante o curso é criado uma API para calcular a melhor condição de surf entre vari
由于现有的node weixin api接口做的比较麻烦,不利于书写与理解.故重新书写代码,架构. 让开发者更容易理解与使用,并且帮助提升软件质量 node-weixin-api是基于node-weixin-*的API接口的SDK。 它们都是由下列子项目组合而成, node-weixin-api只是将业务接口统一到一个api里方便调用,而不必一个一个重新安装: node-weixin-config
我尝试了很多次,但得到以下错误 http://localhost:3001/getlocaiton net::err_connection_delection和createError(createError.js:17)位于xmlHttpRequest.handleerror(xhr.js:87)。