Beacon24 / v0

4 stars 2 forks source link

add nodemon as devDependency + 'dev' npm script #4

Closed lukebelliveau closed 2 years ago

lukebelliveau commented 2 years ago

tl;dr enable users to run the npm run dev command to automatically run the application locally

what changed?

details add 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.