Firstly you need to install node.js on your PC (download from HERE); To check whether it is installed properly, you will need to check node js version in cmd (or in PHPStorm's terminal) by typing:
Then, in your project folder by using PHPStorm's terminal (or the Window's cmd) you need to initialize npm. In the terminal type:
npm init -y
In your project folder this will create node_modules folder with all the packages you are installing. It will also create package.json file with the dependencies information. Npm's file package.json is kind of a recipe/grocery list of our project with npm packages dependencies you are installing.
Next, to install an npm package type in the terminal:
npm install lodash
In this case lodash is the name of the package. Here is another example (installing normalize.css):
npm install normalize.css
...or install couple of necessary npm packages separated by space:
npm install postcss-simple-vars postcss-nested autoprefixer --save-dev
All these packages come from https://www.npmjs.com - you can search there for a package you are interested in.
To run npm you should type:
npm run dev
So why is NPM important for our project?
For example if something happens to our PC (some sort of a crash), we can always recover our project by cloning the project from GitHub (learn how to use GitHub and Git with PHPStorm IDE) and after cloning the project - the package.json file (the resipe of our project) will be inside and after typing in the terminal npm install all of the npm packages will be installed/recovered again! Great! :-)
Here are some npm packages I use with PHPStorm:
Definitely use webpack-dev-server; Here is how to install this great automation npm package. Just type:
npm install webpack-dev-server --save-dev
For Lazy loading of the images I am using: lazysizes
You can install it by typing:
npm install lazysizes