0

I'm just starting out with npm, and as far as I understand the npm install command should automatically update the package.json file, but with me it unfortunately doesn't.

I'm on OSX and in a new dir called npmtest I did the following:

$ ls # let's first confirm the folder is empty $ $ npm init --y Wrote to /Users/kramer65/Downloads/npmtest/package.json: { "name": "npmtest", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" } 

I then installed underscore:

$ npm install underscore [email protected] /Users/kramer65/Downloads/npmtest └── [email protected] npm WARN [email protected] No description npm WARN [email protected] No repository field. 

which seems to be installed fine:

$ ls -l total 8 drwxr-xr-x 3 kramer65 staff 102 Oct 18 17:47 node_modules -rw-r--r-- 1 kramer65 staff 221 Oct 18 17:47 package.json 

unfortunately npm list complains that it's not in the package.json file with the extraneous flag:

$ npm list [email protected] /Users/kramer65/Downloads/npmtest └── [email protected] extraneous npm ERR! extraneous: [email protected] /Users/kramer65/Downloads/npmtest/node_modules/underscore 

Which I can confirm:

$ cat package.json { "name": "npmtest", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" } 

The question is; why isn't it entered in the package.json file? Shouldn't that go automatically? What am I doing wrong here? All tips are welcome!

2
  • 1
    npm install doesn't update the package.json file, npm install *module name* --save updates the json package. Commented Oct 18, 2017 at 15:57
  • 1
    @ZombieChowder - Ah, thanks. Can you add that as an answer so that I can accept it? Commented Oct 18, 2017 at 15:58

1 Answer 1

2

npm install doesn't update the package.json file, npm install *module name* --save updates the json package. Hope that helps.

Sign up to request clarification or add additional context in comments.

5 Comments

Slight clarification - NPM v5 does update the package.json without --save if you do npm install modulename. Your answer is correct for older versions, though.
@JoeClay yes buuuut in most cases the latest version is never used for development or production. Idk, I just presumed so.
I think that's a fair assumption, yeah. v4 is still the default in the current LTS version of Node.
@JoeClay - Thanks for the tip. Since I'm just starting out with Node and npm I simply upgraded to NPM v5 and I'll forget about it for now. Always good to be able to forget about legacy when you're starting out afresh.. :-)
@kramer65: NPM 5 becomes the default in a few weeks I think (once Node 8 moves to long term support), so you're not too far ahead of everyone else :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.