1

As per this post it is possible to install npm packages first and then create package.json at a later point of time.

I have installed nodeJs in my computer. In a simple empty folder when I run the command npm install jQuery I get 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 a plain HTML javascript project. I want to use npm simply to get latest packages or the javascript files. I don't want to do npm init before installing the packages as this is not some reactJs kind of application.

RBT
  • 21,293
  • 19
  • 144
  • 210
  • 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

2

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
  • 3,755
  • 1
  • 19
  • 39
1

It was a mistake from my end as I couldn'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).

Simply 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
  • 21,293
  • 19
  • 144
  • 210
-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,027
  • 11
  • 23