I'm trying to run this HTML minifier from an Ubuntu command-line.
But I'm getting an error when I try to do so.
NodeJS and NPM installs fine:
root$ apt-get install -y nodejs npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
nodejs is already the newest version.
npm is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Installing the html-minifier seems to work:
root$ npm install html-minifier -g
npm http GET https://registry.npmjs.org/html-minifier
<... SNIP ...>
npm http 304 https://registry.npmjs.org/source-map
/usr/local/bin/html-minifier -> /usr/local/lib/node_modules/html-minifier/cli.js
html-minifier#3.5.9 /usr/local/lib/node_modules/html-minifier
├── commander#2.14.1
├── ncname#1.0.0 (xml-char-classes#1.0.0)
├── relateurl#0.2.7
├── he#1.1.1
├── param-case#2.1.1 (no-case#2.3.2)
├── camel-case#3.0.0 (upper-case#1.1.3, no-case#2.3.2)
├── clean-css#4.1.9 (source-map#0.5.7)
└── uglify-js#3.3.12 (source-map#0.6.1)
I can see that the html-minifier is installed:
root$ which html-minifier
/usr/local/bin/html-minifier
root$ head -5 /usr/local/bin/html-minifier
#!/usr/bin/env node
/**
* html-minifier CLI tool
*
* The MIT License (MIT)
But when I try to run it, I get the following error:
root$ html-minifier
/usr/bin/env: node: No such file or directory
Why can't I run the html-minifier? What am I doing wrong? And how can I fix it??
On ubuntu, node is called nodejs. Two options I can see
Edit the file "/usr/local/bin/html-minifier" and change #!/usr/bin/env node to #!/usr/bin/env nodejs
Add a small script node to start nodejs for you, or try alias node=nodejs
Related
I'm doing some work on a command line interface, and to test it from the root of the project I do:
npm i -g
After this I can test the command on various projects.
IIUC running npm i -g creates global links that are executable, but the actual files being run are the original project files?
Running:
ole#mki:~/SuperflyCSS/cli$ npm list -g | grep superfly
├─┬ #superflycss/cli#4.1.2 -> /home/ole/SuperflyCSS/cli
│ ├─┬ #superflycss/pli#3.0.0
Seems to indicate that this is the case.
I just want to triple check because I'm getting an odd scenario where it looks as if NPM is making a copy.
This issue is related to this issue.
Globally installed modules are placed in "/usr/local/lib/node_modules" (or its equivalent on your system, which you can find by running "npm list -g").
As for the binaries that are globally installed, symbolic links to them are placed in "/usr/local/bin", but you can find out where they are on your system by using "npm bin -g".
For example, browserify installed to "/usr/local/lib/node_modules/browserify", and has a "/bin/cmd.js" file that is linked as:"/usr/local/bin/browserify->/usr/local/lib/node_modules/browserify/bin/cmd.js".
I ran into an issue today mid-class. I was showing my class how to install and use gulp.js, so I had to show the process on a projector.
I've installed node.js and gulp.js globally with npm install -g gulp and it all works fine.
But when I try to install gulp locally in the project folder I am working on, it looks like gulp is installed, but the node_modules folder is never created.
I tried refreshing, I tried running the command prompt as admin, I've checked for hidden folders, nothing works. --- I even restarted and tried again, cause Windows.
I am working on windows 10.
Transcript of command line output:
C:\Xampp\htdocs\test> node -v
v4.2.4
C:\Xampp\htdocs\test> npm -v
2.14.12
C:\Xampp\htdocs\test> gulp -v
[16:40:28] CLI version 3.9.1
[16:40:28] Local version 3.9.1
C:\Xampp\htdocs\test> npm install --save-dev gulp
npm WARN deprecated minimatch#2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch#0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs#1.2.3: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs#^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
gulp#3.9.1 ..\..\..\node_modules\gulp
├── interpret#1.0.1
├── pretty-hrtime#1.0.3
├── deprecated#0.0.1
├── archy#1.0.0
├── minimist#1.2.0
├── tildify#1.2.0 (os-homedir#1.0.2)
├── semver#4.3.6
├── v8flags#2.0.11 (user-home#1.1.1)
├── chalk#1.1.3 (escape-string-regexp#1.0.5, supports-color#2.0.0, ansi-styles#2.2.1, strip-ansi#3.0.1, has-ansi#2.0.0)
├── orchestrator#0.3.8 (stream-consume#0.1.0, sequencify#0.0.7, end-of-stream#0.1.5)
├── gulp-util#3.0.8 (array-differ#1.0.0, lodash._reescape#3.0.0, beeper#1.1.1, lodash._reevaluate#3.0.0, array-uniq#1.0.3, object-assign#3.0.0, lodash._reinterpolate#3.0.0, dateformat#2.0.0, replace-ext#0.0.1, has-gulplog#0.1.0, fancy-log#1.3.0, vinyl#0.5.3, gulplog#1.0.0, lodash.template#3.6.2, through2#2.0.3, multipipe#0.1.2)
├── vinyl-fs#0.3.14 (strip-bom#1.0.0, vinyl#0.4.6, defaults#1.0.3, graceful-fs#3.0.11, through2#0.6.5, mkdirp#0.5.1, glob-stream#3.1.18, glob-watcher#0.0.6)
└── liftoff#2.3.0 (lodash.isstring#4.0.1, lodash.isplainobject#4.0.6, lodash.mapvalues#4.6.0, extend#3.0.0, rechoir#0.6.2, flagged-respawn#0.3.2, resolve#1.2.0, fined#1.0.2, findup-sync#0.4.3)
Note: npm is in my PATH.
You need either package.json or folder named node_modules in the current directory. If you are not going to have one, npm will look for either one in the parent directories. Check answer to NPM Installs Package Outside Current Directory for more details.
Also it is advised to start with npm init which will create package.json for you.
I am trying to make use of React-Native-Web, but the master branch version of ListView gives the error: TypeError: undefined is not a constructor (evaluating 'new _reactNative.ListView.DataSource')
One of the pull requests on the project adds the ListView functionality I need.
How do I add this PR to my own project?
What I have tried:
created my own fork and manually added the files then tried to use npm to load it directly as per this SO question, it did not work, key core components were missing. The way one normally installs React-Native-Web is npm install --save react#0.14 react-dom#0.14 react-native-web and I tried npm install https:https://github.com/mcampsall/react-native-web
adding the files directly to my /dist folder. This did not work because I needed the babel translated versions of the files. I tried to use the babel REPL to translate them, but it is missing some plugins and gets hung up on certain parts of the code.
Thanks in advance.
EDIT: I just tried npm install --save react#0.14 react-dom#0.14 https://github.com/mcampsall/react-native-web as per Molda's suggestion and got:
├── babel#6.5.2 extraneous
├── babel-plugin-transform-decorators#6.8.0
├── babel-plugin-transform-decorators-legacy#1.3.4
├── babel-preset-react#6.5.0
├── UNMET PEER DEPENDENCY react#0.14.8
├── UNMET PEER DEPENDENCY react-dom#0.14.8
└─┬ react-native-web#0.0.25 (git+https://github.com/mcampsall/react-native-web.git#b448fb94cb29d08057eb72e4c13d09ad808f719a)
├─┬ fbjs#0.8.3
│ └── object-assign#4.1.0
└── react-textarea-autosize#4.0.3
npm WARN react-native-web#0.0.25 requires a peer of react#^15.1.0 but none was installed.
npm WARN react-native-web#0.0.25 requires a peer of react-dom#^15.1.0 but none was installed.
EDIT 2: tried npm install --save react#15.1.0 react-dom#15.1.0 https://github.com/mcampsall/react-native-web and when i do this i get an error npm WARN react-native#0.23.1 requires a peer of react#^0.14.5 but none was installed. which is a different version of react-native-web(0.23.1) than the original error (which was 0.25)...?
I then tried installing react#14.5 and it showed the original error again npm WARN react-native-web#0.0.25 requires a peer of react#^15.1.0 but none was installed.
I just tried this
npm install --save react#15.1.0 react-dom#15.1.0 git+https://git#github.com/mcampsall/react-native-web
and it installs without any error.
Make sure you delete all the packages before you install again or try to install into new empty folder
I am trying to install node in my mac..
i am getting the following error...
i downloaded the node from node site and ran that package...
can you guys tell me why i am facing that errror..when i do npm install
MacBook-Pro:~ Raj$ npm install
npm ERR! install Couldn't read dependencies
npm ERR! package.json ENOENT, open '/Users/Raj/package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/Raj
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path /Users/Raj/package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Raj/npm-debug.log
npm ERR! not ok code 0
Running just "npm install" will look for dependencies listed in your package.json. The error you're getting says that you don't have a package.json file set up (or you're in the wrong directory).
If you're trying to install a specific package, you should use 'npm install {package name}'. See here for more info about the command.
Otherwise, you'll need to create a package.json file for your dependencies or go to the right directory and then run 'npm install'.
I had this problem when trying to run 'npm install' in a Terminal window which had been opened before installing Node.js.
Opening a new Terminal window (i.e. bash session) worked. (Presumably this provided the correct environment variables for npm to run correctly.)
In my case it was due to a bad URL (http:// instead of git://, no .git at the end) for one of the dependencies.
You're likely not in the node directory. Try switching to the directory that you unpacked node to and try running the command there.
In case it helps anyone else - my issue was a rookie error, I had a space in the name line of my package.json and it caused the dependencies to be unreadable.
I came across this, and my issue was using an older version of node (3.X), when a newer version was required.
The error message actually suggested this as well:
...
Make sure you have the latest version of node.js and npm installed
...
So the solution may be as simple as upgrading node/npm. You can easily do this using nvm, the "Node Version Manager"
After you've installed nvm, you can install and use the latest version of node by simply running this command:
nvm install node
For example:
$ nvm install node
Downloading https://nodejs.org/dist/v8.2.1/node-v8.2.1-darwin-x64.tar.xz...
######################################################################## 100.0%
Now using node v8.2.1 (npm v5.3.0)
$ node --version
v8.2.1
In mac you might have downloaded and installed Node js in
/Users/yourusername/Downloads/nodejs-todo-master , so go here and run npm install command, no need of sudo as well., you should get output like this...
underscore#1.4.4 node_modules/underscore
ejs#0.8.8 node_modules/ejs
redis#0.8.6 node_modules/redis
jasmine-node#1.0.28 node_modules/jasmine-node
├── walkdir#0.0.7
├── coffee-script#1.8.0 (mkdirp#0.3.5)
├── requirejs#2.1.15
└── jasmine-reporters#1.0.1 (mkdirp#0.3.5)
express#3.0.6 node_modules/express
├── methods#0.0.1
├── fresh#0.1.0
├── range-parser#0.0.4
├── cookie-signature#0.0.1
├── buffer-crc32#0.1.1
├── cookie#0.0.5
├── commander#0.6.1
├── mkdirp#0.3.3
├── debug#2.1.0 (ms#0.6.2)
├── send#0.1.0 (mime#1.2.6)
└── connect#2.7.2 (pause#0.0.1, bytes#0.1.0, formidable#1.0.11, qs#0.5.1)
First download json package file from https://github.com/npm/read-package-json
and then run npm install from terminal.
This is all because you are not in the desired directory. You need to first get into the desired directory. Mine was angular-phonecat directory. So I typed in cd angular-phonecat and then npm install.
If someone is in my situation facing this error and have tried all the above solutions, like:
you are in the right directory
you have a package.json file,
the JSON is valid,
you have tried to run %temp%
you have tried " npm install -d --save"
etc.
Mine worked by doing "npm install --force"
Note: This was also recommended in the error itself, which I didn't pay attention to earlier.
Even " Yarn install" worked.
npm install -d --save worked for me. -d flag command force npm to install your dependencies and --save will save the all updated dependencies in your package.json
For me I'm on windows 10 X64...
My code npm install on cmd failed
So instead of npm i used Yarn
Just type yarn install instead of npm install
This fixed my problem.Tried for 2 days finally found the best
solution
To install yarn , on cmd enter the following code
npm install --global yarn
To check if it has installed correctly enter the following code
yarn --version
Hey if you found error and it stuck while installing then try this
Open run and type %Temp% and delete all file
Then type prefetch on run app an delete all files then try it
These Will do the Job
npm install -g yarn
yarn install
or
npm install --force
Hey if you found error and stcuk while installing packages
,getting only three files like json file ,lock file and module file using yarn then try this using yarn.
Open run and type %Temp% and delete all file
Then type prefetch on run app an delete all files
Then type on CMD npx create -react-app it will give you all packages
In a node.js script that I'm working on, I want to print all node.js modules (installed using npm) to the command line. How can I do this?
console.log(__filename);
//now I want to print all installed modules to the command line. How can I do this?
If you are only interested in the packages installed globally without the full TREE then:
npm -g ls --depth=0
or locally (omit -g) :
npm ls --depth=0
Use npm ls (there is even json output)
From the script:
test.js:
function npmls(cb) {
require('child_process').exec('npm ls --json', function(err, stdout, stderr) {
if (err) return cb(err)
cb(null, JSON.parse(stdout));
});
}
npmls(console.log);
run:
> node test.js
null { name: 'x11', version: '0.0.11' }
list of all globally installed third party modules, write in console:
npm -g ls
in any os
npm -g list
and thats it
Generally, there are two ways to list out installed packages - through the Command Line Interface (CLI) or in your application using the API.
Both commands will print to stdout all the versions of packages that are installed, as well as their dependencies, in a tree-structure.
CLI
npm list
Use the -g (global) flag to list out all globally-installed packages. Use the --depth=0 flag to list out only the top packages and not their dependencies.
API
In your case, you want to run this within your script, so you'd need to use the API. From the docs:
npm.commands.ls(args, [silent,] callback)
In addition to printing to stdout, the data will also be passed into the callback.
Why not grab them from dependencies in package.json?
Of course, this will only give you the ones you actually saved, but you should be doing that anyway.
console.log(Object.keys(require('./package.json').dependencies));
for package in `sudo npm -g ls --depth=0 --parseable`; do
printf "${package##*/}\n";
done
As the end of 2021, there are few obvious way to do it, and a part as the only one give on the answer above this is a complete list.
The Node.js Documentation is actually pretty well explained regarding the matter, this is a collective list of the main commands.
All Commands will run the list of installed modules Locally. In order to run global level just add a -g flag at the end of the statement.
See the version of all installed npm packages, including their dependencies.
❯ npm list
>>> /Users/joe/dev/node/cowsay
└─┬ cowsay#1.3.1
├── get-stdin#5.0.1
├─┬ optimist#0.6.1
│ ├── minimist#0.0.10
│ └── wordwrap#0.0.3
├─┬ string-width#2.1.1
│ ├── is-fullwidth-code-point#2.0.0
│ └─┬ strip-ansi#4.0.0
│ └── ansi-regex#3.0.0
└── strip-eof#1.0.0
Get only your top-level packages
npm list --depth=0
Get the version of a specific package by specifying its name.
npm list <package-name>
See what's the latest available version of the package on the npm repository
npm view <package-name> version
Install an old version of an npm package using the # syntax
npm install #
npm install cowsay#1.2.0
Global package
npm install -g webpack#4.16.4
Listing all the previous versions of a package
npm view cowsay versions
[ '1.0.0',
'1.0.1',
'1.0.2',
'1.0.3',
'1.1.0',
'1.1.1',
'1.1.2',
'1.1.3',
....
]
Update all the Node.js dependencies
Install new minor or patch release
npm update
Install new minor or patch release but not update package.json
npm update --no-save
To discover new releases of the packages, this gives you the list of a few outdated packages in one repository that wasn't updated for quite a while
npm outdated
Some of those updates are major releases. Running npm update won't update the version of those. Major releases are never updated in this way because they (by definition) introduce breaking changes, and npm wants to save you trouble.
To update all packages to a new major version, install the npm-check-updates package globally:
npm install -g npm-check-updates
ncu -u
This will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version
Dev Dependency
Install in development dependencies.
npm install <package-name> -D
npm install <package-name> --save-dev # same as above
Avoid installing those development dependencies in Production with
npm install --production
Uninstalling npm packages
npm uninstall <package-name>
npm uninstall -g <package-name> # globally uninstall
Uninstall a package and ** remove the reference in the package.json**
npm uninstall <package-name> -S
npm uninstall <package-name> --save # same as above
Some commands with global flag examples.
npm list -g
npm list --depth=0 -g
npm list <package-name> -g
npm view <package-name> version -g
Additional Commands
Answer by #prosti
Documentation
Find the installed version of an npm package
Install an older version of an npm package
Update all the Node.js dependencies to their latest version
Semantic Versioning using npm
Uninstalling npm packages
npm global or local packages
npm dependencies and devDependencies
The npx Node.js Package RunnerTABLE OF CONTENTS