tl;dr
enable users to run the npm run dev command to automatically run the application locally
what changed?
add nodemon to devDependencies
add dev npm script -- allows us to run npm run dev from the command line, which in turn runs nodemon index.js
detailsadd nodemon as devDependency
This changes package.json to add nodemon to devDependencies. This means that when a user clones this repo and does npm install, nodemon will be installed into the local node_modules folder inside the project.
You are able to run nodemon index.js because you have nodemon installed on your machine globally. We cannot make this assumption for all collaborators (for example, I did not have nodemon installed on my machine, so nodemon index.js doesn't "just work".
note on the difference between dependencies and devDependencies: in the future when you package this up into a production application, devDependencies are not included in the production bundle. This isn't so important to worry about right now.
To make this change, I ran npm install --save-dev nodemon from the command line. With this command, npm automatically made changes to the package.json and package-lock.json files.
dev npm script
I manually made this change to package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon index.js"
},
All this does is make it so that if you run npm run dev from the project folder, npm will run nodemon index.js. This works, now that nodemon has been installed as a project dependency.
tl;dr enable users to run the
npm run dev
command to automatically run the application locallywhat changed?
nodemon
todevDependencies
dev
npm script -- allows us to runnpm run dev
from the command line, which in turn runsnodemon index.js
details add
nodemon
as devDependency This changespackage.json
to addnodemon
todevDependencies
. This means that when a user clones this repo and doesnpm install
,nodemon
will be installed into the localnode_modules
folder inside the project.You are able to run
nodemon index.js
because you havenodemon
installed on your machine globally. We cannot make this assumption for all collaborators (for example, I did not have nodemon installed on my machine, sonodemon index.js
doesn't "just work".note on the difference between
dependencies
anddevDependencies
: in the future when you package this up into a production application,devDependencies
are not included in the production bundle. This isn't so important to worry about right now.To make this change, I ran
npm install --save-dev nodemon
from the command line. With this command, npm automatically made changes to thepackage.json
andpackage-lock.json
files.dev
npm script I manually made this change topackage.json
:All this does is make it so that if you run
npm run dev
from the project folder, npm will runnodemon index.js
. This works, now thatnodemon
has been installed as a project dependency.