'npm-install command not working

i am new to nodejs. i was trying to install nodejs as per documentation. while using npm install command to install dependencies, i faced an error.

C:\Program Files\nodejs>npm install
npm ERR! install Couldn't read dependencies
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.3.1
npm ERR! npm  v2.14.12
npm ERR! path C:\Program Files\nodejs\package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! package.json ENOENT: no such file or directory, open 'C:\Program Files\
nodejs\package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directo
ry.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Program Files\nodejs\npm-debug.log

C:\Program Files\nodejs>

after running npm install command in folder where package.json file is present it gives this error:

C:\Program Files\nodejs>npm install
npm ERR! install Couldn't read dependencies
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.3.1
npm ERR! npm  v2.14.12
npm ERR! path C:\Program Files\nodejs\package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! package.json ENOENT: no such file or directory, open 'C:\Program Files\
nodejs\package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directo
ry.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Program Files\nodejs\npm-debug.log

C:\Program Files\nodejs>

link for npm-debug log file.. any help would be appreciated.. thanks..



Solution 1:[1]

to install dependencies node looks for a file in the root of the project called package.json, where you have the list of all the dependencies needed for the project. its content looks like something like this:

sounds like you are missing package.json in the root of your project.

to install a dependency you usually run a command like

npm install NAMEOFTHEDEPENDENCY --save-dev

where NAMEOFTHEDEPENDENCY could be grunt-contrib-sass for example

this also automatically updates your package.json

Solution 2:[2]

After installing nodejs try closing your code editor, reopen and run npm install in the same directory as package.json file, forgot to mention, did you install nodejs from https://nodejs.org/en/download/?, thats the first part.

Solution 3:[3]

In order for npm install to work, you need to be in the same directory as your package.json file. npm install then looks at the package.json and installs all the dependancies there.

https://docs.npmjs.com/files/package.json

https://docs.npmjs.com/getting-started/installing-npm-packages-locally

Solution 4:[4]

You are running npm install in nodejs folder, you should run it in the project folder. Just make sure npm is in your path.

Solution 5:[5]

Start with

npm init

this will create package.json file (you will be asked for some data to fill it). Then npm intall <package> [--save|saveDev] will work properly.

Solution 6:[6]

in my case, I was running the command in a wrong file path, just returned to the correct path and everything went alright

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 valerio0999
Solution 2 Awro
Solution 3 Leon Gaban
Solution 4 george.cz
Solution 5 Seti
Solution 6 HibaHasan