Hi, I've heard that if I install Node.js on my PC I can better organize and automate my programming and web developing work by installing and using various NPM packages...
I have some questions:
- Can you please share how do you install NodeJS and npm on PHPStorm and maybe some tricks/hacks on working automation so the dev process is easier?
- Do you have favourite npm packages you would recommend?
- Maybe some npm packages which you use on a daily basis? Like automatic browser refreshing?
Thanks!
Hi,
Firstly you need to install node.js on your PC (download from AQUI); To check whether it is installed properly, you will need to check node js version in cmd (or in PHPStorm's terminal) by typing:
node -v
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