When I run the following commands one by one in Terminal it works and installs,
sudo npm install supervisor
sudo npm install forever
It asks for the admin password in Terminal window and installs fine.
In AppleScript I run this as,
tell application "Terminal"
do script "sudo npm install supervisor" in window 1
end tell
tell application "Terminal"
do script "sudo npm install forever --global" in window 1
end tell
It opens Terminal and asks the password and waits for user response to enter the password to continue. I tried the following AppleScript,
do shell script "sudo npm install supervisor" with administrator privileges
do shell script "sudo npm install forever --global" with administrator privileges
And got the following error,
error "sudo: npm: command not found" number 1
The AppleScript needs to ask for the password once in the common enter the username and password dialog and run the,
sudo npm install supervisor
sudo npm install forever
In Terminal without asking for password in Terminal window. How to do it?
https://developer.apple.com/library/mac/technotes/tn2065/_index.html
Shell scripts do not by default have your path exported into them with apple script. In addition, they are run in shell instead of your default Terminal shell (most likely bash). You should include the full path to npm (/usr/local/bin/npm for me; find using which npm) instead of just npm when trying to run an apple script.
However, when you specify the full path to npm, you run into another problem. npm can't find node in the path. The solution I found to work was to export PATH in the apple script.
export PATH=$PATH:/usr/local/bin; sudo npm install forever
Double check that /usr/local/bin contains both node and npm. This should allow you to successfully install without being prompted.
Related
enter image description here
When i tried to install nodemon package using npm i got errors as shown in the picture. I also tried using sudo but nothing changed.
you can use this command.
sudo npm install nodemon -g
sudo makes sure that the command would run as a superuser that allows users to run programs with the security privileges of another user (normally the superuser, or root).
-g instructs npm to install the node package globally onto the system.
So i've been trying to download and install node.js and npm to should allow me to run expo on my computer. More especifically the cmd "npm install expo-cli --global". When i run it i get the error(s) below. Now, i'm a novice in terminal and navigation of the computer in general, so i'm having troubles underestanding the errors, or what the solution might be. Any help is appreciated
To install a package globally you have to install with root permissions (similar to "Run As Administrator" on windows). You can run:
sudo npm install expo-cli --global
And enter your password at the prompt (keep in mind that even though it won't show up, it's still there).
An alternative solution (if you're not administrator or don't want to use sudo) is giving npm a prefix and adding that to your path. There's a nice guide for that on GitHub: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
I have Node/NPM installed on my (Linux) system. When I use an ordinary terminal, or the terminal inside VS Code, I can run npm commands just fine.
However, when I try to use the "NPM Scripts" feature of VS Code (which lets you run your package.json scripts from a pane in the "Explorer"), I see:
> Executing task in folder MyProject: npm run start <
/bin/sh: 1: npm: not found The terminal process terminated with exit
code: 127
Terminal will be reused by tasks, press any key to close it.
It seems like VS Code uses a different user/shell/path/something to run these scripts, and as a result it can't find the npm command ... but I have no idea what it's using or how to fix it.
For some reason "NPM Scripts" function needs the npm file to be in /usr/local/bin/npm. Try using your linux package manager to install npm (ex: sudo apt-get install npm) or install node.js again with the package from the website.
Another option would be to create a soft-link in /usr/local/bin/ pointing to the current installation.
I'm learning nodeJs. I managed to run nodejs commands on cmd and it works fine. Now I want to install express framework and for that in the tutorial I'm following it asks to type sudo install -g express on npm command prompt. So I typed npm in my windows search, and clicked on it. Right after few seconds less than 3 it closes straight away.
I found that npm.cmd exist in nodejs directory where node.exe found. What could be the problem here. If I were to type the above mentioned command in windows cmd, it says sudo is unrecognized program.SO must I use npm cmd?
After running cmd.exe , I guess you would have node installed but still run node -v , it should respond with the version meaning it's working.
Now if you want to explicitly install express.js you just have to run on, the command prompt itself,
npm install express -g.
Anyways you can follow this link from their official website. Hope it helps. Also sudo is a program for Unix like operating systems, just in case you needed it.
I keep getting this error when the towerjs post install script runs
npm ERR! Error: EACCES, open '/home/claire/.npm/e18f6569-thub-com-viatropos-coffeecup-git.lock'
I've tried sudo, and -g but I think it's because the post install script doesn't include sudo. I can install coffeecup on its own, but the tower sub install fails.
Login with root to finish installation correctly.
For Ubuntu:
Set root password if it not defined yet:
sudo passwd
Change user to root
su
Install tower
npm install tower -g
This way works for me.
Note: not work if you change user to root with sudo -s command. Works only with su.