Configuration is easy, just like the other libraries used in the previous sections with npm.
- Start by running the following command:
$ npm install mongoose --save
- Also install the TypeScript @types:
$ npm install @types/mongodb @types/mongoose --save-dev
So far, our package.json file should look as follows:
{
"name": "order-api",
"version": "1.0.0",
"description": "This is the example from the Book Hands on RESTful APIs with TypeScript 3",
"main": "./dist/server.js",
"scripts": {
"build": "npm run clean && tsc",
"clean": "rimraf dist && rimraf reports",
"lint": "tslint ./src/**/*.ts ./test/**/*.spec.ts",
"lint:fix": "tslint --fix ./src/**/*.ts ./test/**/*.spec.ts -t verbose",
"pretest": "cross-env NODE_ENV=test npm run build && npm run lint",
"test": "cross-env NODE_ENV=test mocha --reporter spec --compilers ts:ts-node/register test/**/*.spec.ts --exit",
"test:mutation": "stryker run",
"stryker:init": "stryker init",
"dev": "cross-env PORT=3000 NODE_ENV=dev ts-node ./src/server.ts",
"prod": "PORT=3000 npm run build && npm run start",
"tsc": "tsc"
},
"engines": {
"node": ">=8.0.0"
},
"keywords": [
"order POC",
"Hands on RESTful APIs with TypeScript 3",
"TypeScript 3",
"Packt Books"
],
"author": "Biharck Muniz Araújo",
"license": "MIT",
"devDependencies": {
"@types/body-parser": "^1.17.0",
"@types/chai": "^4.1.7",
"@types/chai-http": "^3.0.5",
"@types/express": "^4.16.0",
"@types/mocha": "^5.2.5",
"@types/mongodb": "^3.1.17",
"@types/mongoose": "^5.3.5",
"@types/node": "^10.12.12",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"mocha": "^5.2.0",
"rimraf": "^2.6.2",
"stryker": "^0.33.1",
"stryker-api": "^0.22.0",
"stryker-html-reporter": "^0.16.9",
"stryker-mocha-framework": "^0.13.2",
"stryker-mocha-runner": "^0.15.2",
"stryker-typescript": "^0.16.1",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.17.0",
"typescript": "^3.2.1"
},
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"halson": "^3.0.0",
"js2xmlparser": "^3.0.0",
"lodash": "^4.17.11",
"mongoose": "^5.4.0"
}
}
With Mongoose configured, we will move on to create schemas.