Home > Software design >  Using NPM command within a project (Beginner question)
Using NPM command within a project (Beginner question)

Time:12-04

I created a project folder and inside this folder I ran npm init.

Then I ran npm install minify --save. Now I would like to use the command minify css/style.css > css/style.min.js.

However I get as error: zsh: command not found: minify.

I am aware that if I install the package globally with npm install minify -g that it will work. However, I would like to have it available only inside the project folder. Or am I fundamentally misunderstanding something?

CodePudding user response:

To use the minify command in your project, you need to run it through npm. To do this, you can use the npx command, which is included with npm. Here is an example:

npx minify css/style.css > css/style.min.js

Alternatively, you can run the minify command through npm by using the run command, like this:

npm run minify -- css/style.css > css/style.min.js

Keep in mind that the minify command may not be available if you are in a different directory than the one where you ran npm install minify --save. In that case, you will need to run the npm run or npx commands from the directory where you ran npm install.

Hope this helps!

  • Related