Node.js REST API sample code using followings
- Node.js & Express
- MongoDB & Mongoose
- tsoa & swagger-ui-express
- OpenAPI-compliant REST APIs using TypeScript and Node
- https://github.com/lukeautry/tsoa
- Jest & Supertest & mongodb-memory-server for Unit test
- All in TypeScript
- hello: Simple and Minimalism sample API
- todos: TSOA and Swagger based simple Todo CRUD
cd server
npm init --yes
npm install --save-dev typescript @types/node
npx tsc --init
npm install --save-dev eslint
npx eslint --init
# this will suggest to install
# @typescript-eslint/parser @typescript-eslint/eslint-plugin
npm install --save-dev jest @types/jest ts-jest
npx ts-jest config:init
npm install express
npm install --save-dev @types/express
npm install --save-dev tsc-watch # c.f. ts-node-dev
npm install --save-dev supertest @types/supertest
npm install mongoose
npm install --save-dev @types/mongoose
# In-Memory MongoDB
# https://github.com/nodkz/mongodb-memory-server
npm install --save-dev mongodb-memory-server
npm install tsoa swagger-ui-express
npm install --save-dev @types/swagger-ui-express
npx tsc --init
- start local MongoDB mongodb/README
npm run dev
open http://127.0.0.1:3000/
curl 127.0.0.1:3000/hello?name=Alice
curl -X POST 127.0.0.1:3000/hello -d "name=Bob"
curl 127.0.0.1:3000/hello
npm run test
npm run test:coverage
open coverage/lcov-report/index.html
- REST API framework + swagger spec generator
tsoa spec-and-routes
will generateroutes.ts
- c.f.
npm run dev
inpackage.json
- c.f.
npm run dev
# run test from swagger doc
open http://127.0.0.1:3000/docs
- expressの開発にTypeScriptを利用する
- TypeScript で Express サーバを実装するためのボイラープレートを作った
- Node.js + Express + TypeScript: Unit Tests with Jest
- TypeScriptの環境: tsc-watch で ts ファイルの変更監視&アプリの再起動を自動化する
- express と jest だけでサックリとテストを書く!
- Configure Jest - TypeScript - Node.js - Express
- Jestを使ってみてのハマりどころメモ
- jestでモックしてみたメモ
- 2.4 Saving to a Database - Working with Data and APIs in JavaScript
- using NeDB (subset of MongoDB)
- https://www.youtube.com/watch?v=xVYa20DCUv0
- Express + TypeScript + Mongo Part 4 - Swagger
- MongoDB + Jestのテスト方法
- Unit Testing Node.js + Mongoose Using Jest