NPM
- Local install (default): puts stuff in ./node_modules of the current package root.
- Global install (with -g): puts stuff in /usr/local or wherever node is installed.
- Install it locally if you’re going to require() it.
- Install it globally if you’re going to run it on the command line.
- If you need both, then install it in both places, or use npm link.
First of all, need to install package.json on working directory cd/
//The very beginning, create your package.json with init npm init //You can get a default package.json by running npm init with the --yes or -yflag: npm init --yes //To set init cinfiguration manually, here's some handy command: npm set init.author.email "[email protected]" npm set init.author.name "ag_dubs" npm set init.license "MIT" //Then install npm in working directory npm install //Install gulp globally npm install gulp -g //Install gulp locally $ npm install gulp --save-dev //Create directory |- app/ |- css/ |- fonts/ |- images/ |- index.html |- js/ |- scss/ |- dist/ |- gulpfile.js |- node_modules/ |- package.json //Note for Git users: Node.js installs modules to a node_modules folder. You should add this to your .gitignore //When deploying the project to another PC, you can run npm install to restore them. //Click here for more information about gulp setup //Install package npm install fotorama
//To call dist files directly from node_modules for app.scss (scss parent) // vendor @import "../../../../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; $fa-font-path : '/node_modules/font-awesome/fonts'; @import "../../../../../node_modules/font-awesome/scss/font-awesome"; // @import "vendor/dropzone"; @import "../js/plugins/jquery-filestyle/src/jquery-filestyle.min.css"; @import "components/fotorama/fotorama";
Package name | Description | Command |
---|---|---|
nightmare | Nightmare is a high-level browser automation library. | |
npm-watch | The keys of the "watch" config should match the names of your "scripts", and the values should be a glob pattern or array of glob patterns to watch. | |
webpack | webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset. | //Install with npm: npm install --save-dev webpack //Install with yarn: yarn add webpack --dev |
Fotorama | Fotorama slider for npm. Quite handy and powerful | |
Font Poppins | Install Poppins font | npm install --save typeface-poppins |
npm uninstall fotorama //uninstall package npm uninstall --save fotorama //To remove it from the dependencies in package.json, you will need to use the save flag cd my-app > npm start // start application by type the command npm init //creates a package.json in root for you npm list //lists all installed packages npm i bootstrap@3 //npm install specific version npm view extract-text-webpack-plugin versions //to view available package versions npm -v prints: 5.0.1 node -v prints: 7.2.1 npm config get registry prints npm prune //removes packages not depended on by your project according to your package.json npm outdated tells you which installed packages are outdated with respect to what is current in the npm registry but allowable by the version definition in your package.json rm -rf node_modules && npm install //remove all node and reinstall npm update/ npm upgrade //This command will update all the packages listed to the latest version (specified by the tag config), respecting server. //It will also install missing packages. As with all commands that install packages, the --dev flag will cause devDependencies to be processed as well. //If the -g flag is specified, this command will update globally installed packages. //If no package name is specified, all packages in the specified location (global or local) will be updated.
Function | Command | NPM equivalent |
---|---|---|
To install yarn | npm install -g yarn | N/A |
Check yarn version | yarn --version | yarn -v |
Install/Add new dependencies | yarn add | npm i/install |
To remove dependencies | yarn remove | npm uninstall |