Add path to node in package.json - node.js

I use Plesk and CentOS. My npm and node bin are in a specific folder :
/opt/plesk/node/9/bin
When I try to run /opt/plesk/node/9/bin/npm install, I have this error :
node-sass#4.10.0 install /var/www/app/node_modules/node-sass
node scripts/install.js
sh: node: command not found
I guess it's because Plesk doesn't set PATH for node, I have multiple versions of Node.
Can I set the path to node in the package.json of my project ? or set this path in an other way ?

Because Node binary was not found by npm due to no node binary in the current PATH.
Try add the variable into a global npm config file. Using shell command:
echo "scripts-prepend-node-path=true" >> /opt/plesk/node/9/etc/.npmrc
Or you can use File Manager of PleskUI to add scripts-prepend-node-path=true into .npmrc file. Create the file if it does not exist.

Related

npm webpack: coomand not found

I'm running this command on linux:
sudo npm install -g webpack
I'm getting the following output:
/home/igor/.npm-global/bin/webpack ->
/home/igor/.npm-global/lib/node_modules/webpack/bin/webpack.js
/home/igor/.npm-global/lib └── webpack#1.13.3
which looks perfectly legit, but when I try to use:
webpack -h
I get the
webpack: command not found
How can I make webpack running from the command prompt?
The default directory for globally installed NPM modules is /usr/local, which will install the module binaries inside bin folder.
If you echo your $PATH environment variable you'll see that /usr/local/bin is in your path. That means when you run a command like webpack, macOS will try to find the binary in this folder or any other folder on your $PATH.
At some point you probably changed it to ~/.npm-global, which installed webpack binary into your /home/igor/.npm-global/bin/. As this folder is not in you $PATH, macOS did not find it. You can run npm config get prefix to confirm this.
Solution 1 is to add it to your path by changing your ~/.profile file. Just append export PATH=~/.npm-global/bin:$PATH to it and restart your terminal.
Solution 2 is to change back the default folder to /usr/local by running npm config set prefix '/usr/local'. In this case you won't need to change your PATH variable.
Try to install webpack localy on the path you're working with.

Run npm command line without add node to path

I have a folder with last version of node and npm (on ubuntu) :
node
node_modules
node
npm
npm.cmd
And would like to run node/npm without add node/node in classpath
Because node/npm returns :
node/npm: node: not found
Idea ?
What you can do is to call the npm-cli.js using node. So in the node folder, you can run npm commands by running:
./node node_modules/npm/bin/npm-cli.js <command> <args>
where and are the npm command and arguments.
This is impossible.
Any executable that you run by writing its name (not including the path) is looked in some pre-defined paths.
If you'd like to run an executable located in some directory, you can execute it only by specifying its full or relative paths.
If you change dir to the containing directory, you can run it by
./executable-name
In your case
./node

Install NodeJS package locally

When i try to install package on my local directory using npm install connect,but it just keep pop up some warning about
no such file or directory, open '/Users/felixfong/package.json'
But i don't not want to install package at my computer directory,i want to install at my local web app directory
Are you sure you are inside your local web app directory when you run the npm install connect command?
cd app-directory/
npm install connect
Also ensure that a package.json file is also present in the app-directory.
If it isn't present, you can use npm init command to create the package.json file interactively.
You have to go inside your project directory using
Then you can check package.json.
If package.json file is not there then initialize npm using the following command:
npm init
Then your can install the package using the following command:
npm install connect
'npm install connect' does not save the connect npm package in package.json file.
For saving the package into package.json file you have to givt --save option like:
npm install connect --save
Make sure that you are in web app's directory. Current path can be checked via command pwd in Linux and cd in windows. Navigate to your web app directory if you are somewhere else. Check existence of package.json by listing the content of the folder. ls and dir can be used for ubuntu and windows respectively for listing content. Commands for ubuntu are as below:
pwd
cd your-path/
ls
Now Initialize npm in your web app directory if package.json is not already existing there.
npm init
This will ask some information like:
name of the app,
its version,
description,
entry point,
test command,
git repo,
keywords,
author and
license (if any)
You can select default values by leaving the fields empty if you aren't sure or confused about any field. Combining this information as json, npm will create a file named package.json
Just run the desired command now after initialization of npm or if its already initialized:
npm install connect

Node.js and modules on a system where I can't sudo

I would like to use node on a system on which I don't have sudo permissions.
I downloaded node and followed a guide on how to install npm packages globally without sudo permissions.
Node and npm commands works well. My problem is that installed packages (in my case bower and gulp), search for node in /usr/bin/env: node:
So if I run bower I get /usr/bin/env: node: No such file or directory
I can't create a ln in that directory because I don't have permission. How can I tell bower and gulp to search for node in another path?
My problem is that installed packages (in my case bower and gulp), search for node in /usr/bin/env: node:
They most certainly do not. Here is the first line in gulp:
#!/usr/bin/env node
It is the same in bower. Note that it does not have any of the two colons that you show.
Your question also suggest you are misinterpreting the error message. There is nothing there that implies you should have sudo capabilities. That message tells you that env is unable to find node. Let me illustrate with a name that does not exist on my system:
$ /usr/bin/env nonexistent
/usr/bin/env: nonexistent: No such file or directory
$ env nonexistent
env: nonexistent: No such file or directory
If I do env node it will start node. The error you are getting is exactly in the form of the error messages above: you get the path used to launch env, which is the full path if that's what was used, the name of the command that was not found and the description of the problem.
Why does it fail? It fails because env is not able to find node among the paths specified in your PATH environment variable.
I don't know what your guide told you but if you install locally, you either have to install in such a way that the binaries of Node will be in a path already covered by your PATH, or you should modify the file that sets your environment variables to add the paths in which node and npm were installed. For bash, you'd modify ~./profile like this:
PATH=/path/to/the/node/binaries:$PATH
I prepend to make sure that the path you want will take precedence over anything that could also be installed in the system locations (/bin, /usr/bin, etc.)
Are you able to edit the bowserrc file?
Bower can be configured using JSON in a .bowerrc file. For example:
{
"directory": "app/components/",
"analytics": false,
"timeout": 120000,
"registry": {
"search": [
"http://localhost:8000",
"https://bower.herokuapp.com"
]
}
}
The config is obtained by merging multiple configurations by this order of importance:
CLI arguments via --config
Environment variables
CLI arguments via --config
Environment variables
Local .bowerrc located in the current working directory
All .bowerrc files upwards the directory tree
.bowerrc file located in user’s home folder (~)
.bowerrc file located in the global folder (/)
Found in:
http://bower.io/docs/config/

Modules are not installing globally with "npm -g install..."

On Ubuntu 12.04 x 64...
npm -g install hiredis redis
Installs fine and npm ls shows those modules, but only when I'm in node source directory
does not show when I'm in any other directory
For kicks, tried running the command while in that other directory- still no dice :(
They are installing globally, but you cannot see them with npm ls, in other directories. Because npm ls only shows local modules. If you want to list global modules you have to type: npm ls -g.
Sometimes another version or just a wrong path is referenced in the npm config file instead of the installed version.
This may cause node/npm to misplace global modules.
To check and fix:
In cmd line type: npm config list
You should get a list of configuration values, one of them is prefix.
Make sure the path in prefix is the same path (only without node.exe) as the actually installed node.exe path.
(this path is listed further down as node bin location)
If it's not, change it:
Either in the config file (in your user folder, named .npmrc)
Or, via cmd line: npm config set prefix "C:\Program Files\nodejs" (change path for ubuntu of course)
Reinstall the module/package you tried to install, don't forget -g for global.

Resources