3

As per this post it is possible to install npm packages first and then create package.json later on.

I have installed nodeJS in my computer. In an empty folder, when I run below command:

npm install jQuery

It gives below error on console:

D:\Rasik\reactJs\learnJs
`-- jquery@3.2.1
npm WARN enoent ENOENT: no such file or directory, open 'D:\Rasik\reactJs\learnJs\package.json'
npm WARN learnJs No description
npm WARN learnJs No repository field.
npm WARN learnJs No README data
npm WARN learnJs No license field.

I'm working on an HTML Vanilla JavaScript (JS) project. I want to use npm to get latest packages or the JS files. I don't want to do npm init before installing the packages as this is not some ReactJS kind of application.

RBT
  • 24,161
  • 21
  • 159
  • 240
  • 4
    Those are not errors but warnings. A folder `node_modules` should be present and the package should be downloaded without issue. – Nico Van Belle Jun 02 '17 at 06:43
  • ohhh...my bad. I didn't even look into the root directory after seeing so many logs on the command shell. Sorry to bother you. Thanks. – RBT Jun 02 '17 at 06:45
  • You can refer https://docs.npmjs.com/files/package.json for info – Rajesh Jun 02 '17 at 06:46

3 Answers3

4

You can install npm packages without package.json by just running npm install <package name>, but it is not recommended. Since if you want to push it to Github or so, uploading the entire node modules is going to be a pain.

It is very easy to set up a package.json file. You just have to run npm init and press enter key a few times which would use default values, or you can edit the author and keywords and all.

If you're too lazy, just do npm init -y which will initialise package.json with default values

A package.json file is very useful because if you have to share your code, it is very hard without a package.json file since you'll have to copy all folders in node_modules. If you have a package.json, all you have to do is run npm install, which will download all packages on its own

illiteratewriter
  • 4,155
  • 1
  • 23
  • 44
1

It was a mistake from my end as I didn't notice node_modules directory. There is no additional effort or prerequisite involved in installing or uninstalling a package through NPM. Any node package can be installed even without having package.json file in your root directory (which is created through npm init command).

Running npm install jQuery results in installation of jQuery module. It creates \node_modules\jquery directory in root with all the relevant files.

Additionally, package name for npm install command is case insensitive so all following commands are equivalent:

npm install jquery
npm install jQuery
npm install jQuErY
RBT
  • 24,161
  • 21
  • 159
  • 240
-1

Have you tried running npm config get save to check if the --save value is set to true/false?

As mentioned in this topic.

mitpatoliya
  • 2,037
  • 12
  • 23