Installing dependencies with npm and package.json

As we have explained, if you have package.json, then you can define both dependencies and devDependencies. Here's an example:

{   "name": "npm-install-example",   "version": "1.0.0",   "description": "",   "main": "index.js",   "scripts": {     "test": "echo \"Error: no test specified\" && exit 1"   },   "author": "dSebastien <seb@dsebastien.net>    (https://www.dsebastien.net)",   "dependencies": {     "lodash": "4.17.11"   },   "devDependencies": {     "karma": "3.0.0"   } } 

In this example, we have defined the dependencies section and we have added a dependency in relation to the 4.17.11 version of the lodash (https://lodash.com) library. In devDependencies, we have defined a dependency in relation to the ...

Get Learn TypeScript 3 by Building Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.