30
loading...
This website collects cookies to deliver better user experience
npm install
CLI command efficiently with different ways of installing a package.npm is the world's largest software registry. Open-source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.
npm-install-ways
.mkdir npm-install-ways
cd npm-install-ways/
npm init
and press enter continously for all the prompts to have a default value. Finally, a package.json
file will be created in the same path.npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help init` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (npm-install-ways)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /Users/yuvaraj/Documents/blog article projects/npm-install-ways/package.json:
{
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this OK? (yes)
{
"name": "use-of-typescript",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {}
}
dependencies
& devDependencies
have an empty object. What does that mean?jquery
package. You can install it with the below command.npm install jquery
jquery
package in the node_modules
folder.jquery
to the dependencies
object in the package.json file. {
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.6.0" // <--- this is added
}
}
dependencies
list in package.json.--no-save
argument while installing it.npm install typescript --no-save
typescript
package in the node_modules
folder.package.json
content.{
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.6.0"
}
}
typescript
package is available in node_modules
directory..
└── node_modules
├── jquery
└── typescript
jasmine
package.npm install jasmine --save-dev
package.json
content.{
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.6.0"
},
"devDependencies": {
"jasmine": "^3.8.0" <--- Added jasmine here
}
}
jasmine
package in the node_modules
folder.jasmine
to the devDependencies
object in the package.json file. (Note: It adds to devDependencies
, not under dependencies
)jasmine
package which is 2MB. In the production environment, it is not required to have a jasmine
package. So, If you install all application dependencies with npm install --production
in the production server, it excludes the jasmine
package from your application bundle since it is used only for development purposes. jquery
package version is 3.6.0
. The latest version seems to have some problems. So, you are feeling to revert it to the older version (maybe 3.5.0) to make it work.npm install [email protected]
3.5.0
.node_modules
folder. (It removed 3.6.0 and installed 3.5.0).jquery
version in the dependencies
object in the package.json file.package.json
content.{
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.5.0" <--- changed from 3.6.0 to 3.5.0
},
"devDependencies": {
"jasmine": "^3.8.0"
}
}
jasmine
versions available in npm.jasmine
package in the 3.8.0
version. This version seems to be buggy and you wanted to go back to the last available version. npm install jasmine@"<3.8.0" --save-dev
3.8.0
from npm. In this case, it is 3.7.0
. (See the above screenshot).node_modules
folder. (It removed 3.8.0 and installed 3.7.0).jquery
version in the devDependencies
object in the package.json file.package.json
content.{
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.5.0"
},
"devDependencies": {
"jasmine": "^3.7.0" <--- It updated from 3.8.0 to 3.7.0
}
}
npm install jasmine@">3.0.0 <3.5.0" --save-dev
jasmine
version, which should be above 3.0.0
and lesser than 3.5.0
. In this case, it installs 3.4.0
.jquery
3.3.0 version package from the tar file available in Github tags.npm install https://github.com/jquery/jquery/archive/refs/tags/3.3.0.tar.gz
jquery
Github page.package.json
content.{
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "https://github.com/jquery/jquery/archive/refs/tags/3.3.0.tar.gz" <--- Installed from Github Tarball URL
},
"devDependencies": {
"jasmine": "^3.4.0"
}
}
jquery
version 2 by keeping a customized package name for the jquery version 2.npm install jquery-ver-2@npm:jquery@2
node_modules
folder. The folder will be jquery-ver-2.
jquery
version 2 in the name of jquery-ver-2 in the dependencies
object in the package.json file.package.json
content.{
"name": "npm-install-ways",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "https://github.com/jquery/jquery/archive/refs/tags/3.3.0.tar.gz",
"jquery-ver-2": "npm:jquery@^2.2.4" <--- Jquery 2 is installed as jquery-ver-2.
},
"devDependencies": {
"jasmine": "^3.4.0"
}
}