I have to set-up node environment in my production system. I installed node in my local system its fine, after that i checked for version node -v.
Now i installed node in my production system using sudo apt get install nodejs and now i checked the version node -v nothing happened but i used nodejs -v, its working.
Also in my local system i used node filename.js to run my node app. But in my production system i have to use nodejs filename.js. I dont know why this happening? Also whether it will create problem in my production. Please share your ideas.
It's more linux specific question. You can create a symlink to use node instead of nodejs. Command example here:
sudo ln -sT $(which nodejs) /usr/local/bin/node
This is because your particular distribution of linux already has a node binary.
You're more than likely not using it for anything. You have two options.
rename the pre-installed node to something else, and rename nodejs to node
rename nodejs to node but make sure to adjust your $PATH so that node.js's directory is loading before the pre-installed node
Related
In my ec2 instance I am able to run pm2 command.
But while deploying application through code deployment I get this error.
LifecycleEvent - ApplicationStop
Script - application_stop.sh
[stdout]Stopping any existing node servers
[stderr]/opt/codedeploy-agent/deployment-root/878477e5-6ffb-4175-8e9e-97045ea99290/d-HVRQ58IBL/deployment-archive/application_stop.sh: line 4: pm2: command not found
My application_stop.sh code.
#!/bin/bash
#Stopping existing node servers
echo "Stopping any existing node servers"
pm2 stop main
As per #ranjanistic I checked my pm2 path using which pm2 command and it returned
~/.nvm/versions/node/v16.15.1/bin/pm2
After that I update my application_stop.sh using this below command
~/.nvm/versions/node/v16.15.1/bin/pm2 start main
Also added symbolic link like this to npm, node and pm2.
///this process worked. Thanks #ranjanistic
which npm
which node
which pm2
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/npm
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/node
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/pm2
Still not working
The binary executable reference to your command needs to be available in the environment you're expecting to run it from.
You are using npm to run a pm2 command, which means it is installed as a local module. Therefore you can similarly create another npm script like npm run stop:all with your pm2 command, it should work.
If you're running it in a bash script, the command reference binary should be available in PATH. Or you can also use your command by mentioning its binary path instead of name, independent of wherever the binary is located, for example
If pm2 is installed as a global node module
/usr/bin/pm2 stop main # or whatever the path to the binary is.
Or if pm2 is installed as a node module in project then
./node_modules/bin/pm2 stop main # again, path to pm2 binary can be anything, you'll have to know beforehand
Also, I'd recommend a separate config file for each of your pm2 applications, so that you can use it anywhere without worrying whether your main app is available to pm2 or not.
You may also need to check if npm or node commands are running or not, and based on that you may add the path to your folder containing pm2 in $PATH variable before running the deployment. You can check the path to pm2 manually using which pm2 if it is available.
You need to provide absolute path like this /usr/bin/pm2
I've been creating a JavaScript game for a project recently and have done it completely on the CodePen website. I now am trying to transfer it to WebStorm to turn it into a basic website. However when I try to run my code I get the following error:
I don't know how to fix it, I've looked everywhere and haven't been able to get some help. Any information would be appreciated.
Simple one, basically the error says, I don't know how to interpret this bit of code that you just gave me. You're missing local install of Node.js and NPM. Get the latest versions of these 2, and then go to File -> Settings -> Language&Frameworks -> Node.js and NPM and in the Node interpreter text box, point it to the path of where node.js was installed.
You're running this JavaScript file with Node.js that is probably not installed on your machine. It seems that you want to run and debug your app in the browser instead. For that you need to create a JavaScript run/debug configuration instead as described here: https://www.jetbrains.com/help/webstorm/debugging-javascript-in-chrome.html
On a linux machnie,
Install nodejs and npm
sudo apt-get install nodejs
sudo apt-get install npm
Get the nodejs installation folder
whereis nodejs
Should print something like:
/usr/bin/nodejs /usr/lib/nodejs /usr/include/nodejs /usr/share/nodejs /usr/share/man/man1/nodejs.1.gz
Go to:
Webstorm-> File -> Languages & Frameworks -> Node interpreter
Copy paste the installation folder to the text box.
Mac OS here. Solved the issue with:
$ brew install nodejs
When I run npm install -g <package> it installs the packages in my user/AppData/Roaming/npm/npm_modules/ folder. This sub-folder is not in my PATH so if I try to run the package without explicitly calling the entire path the call fails with a '<package>' is not recognized as an internal or external command, operable program or batch file.
What can I do to fix this?
Thanks
I'm using win8.1 and I found that the nodejs installer didn't add the path to global node modules to the system PATH. Just add %AppData%\npm; to the user variable(since %AppData% dir is depending on user) PATH to fix it.
You will need to log out then log back in for the change to your PATH variable to take effect.
SET PATH=%AppData%\npm;%PATH%
You have to run this line SET PATH=pathtonodejs;%PATH% (where pathtonodejs is where you installed nodejs) once the installation for nodejs is complete and it should work.
It turned the problem was a change in behavior of the module I was using.
I'd been following old tutorials for using Express.js. The old tutorials assumed Express would be in my path after installing it globally, but as of Express v4.0 there's a separate Express module you have to install in order to get it in your path
I have untarred node.js from the tar file given on nodejs.org, but when i try executing my js program through node command nothing happens, but on the other hand nodejs command runs executes the file.
So my question is what's the difference between node command and nodejs command as and will it effect my programs as i didn't build from the source code. And i of that is the reason of this discrepancy.
This is highly dependent on many factors. Mainly, it depends on what node and nodejs in your shell actually are. You can check this using type node / type nodejs and/or which node / which nodejs (or perhaps whereis). This also depends on the OS and the shell.
My guess is that which -a node will yield /usr/sbin/node which is not the nodejs executable and thus why it does not execute your node code. On my system, it is:
/usr/bin/node -> /etc/alternatives/node -> /usr/bin/nodejs
i.e. node is just a symbolic link to nodejs, which is the executable.
You can also create this alias yourself so that it overrides whatever node is for you.
Some of these answers were difficult to understand for me, so I'm going to write the answer that would've helped me.
node is something like a radio telemetry solving program, they just happened to snag the name node first. nodejs is what you're after. So
make sure you:
apt-get install nodejs
then, to fix the lame naming issue, create a symlink. A symbolic link between node and nodejs.
sudo ln -s /usr/bin/nodejs /usr/bin/node
The first part is the original file placement, and then where it should link to.
You could also create an alias in your bash profile, which is also pretty easy.
For sure available 'node' package is not related to nodejs.
Just take a look at this node from here:
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed from node to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.
So it seems like you may purge that radio program with
dpkg --purge node
And then install nodejs via one of common ways f.e. from precompiled deb packages available like this:
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
But nodejs updates faster than packages so after you will get any nodejs version available it's more efficient to use this module for managing nodejs versions - https://github.com/visionmedia/n
At least after some tests this solution looks most suitable for me at mac os.
I am working on a project for an embedded Linux system (busybox made with buildroot). I am wondering if it is possible to use node.js modules socket.io and express without having to install or run npm. The goal is to be able to have buildroot configured to create a busybox image that simply includes node.js, and then place all my javascript files in the proper directory and execute node app.js from the command line to run the node application (which will use socket.io and express).
So, for example on my development machine (That does have node.js and npm installed), I could run npm install socket.io so it would get socket.io and all its dependencies and install it in the node_modules directory of my project. If I place all those files in a directory and move them to the production environment (embedded Linux with just node.js installed and where npm install socket.io was never run) would my application work?
If I place all those files in a directory and move them to the production environment would my application work?
Yes, it would. However, if you do have any binary dependencies, they need to be recompiled, so it's a bit trickier. If you don't, you'll be fine.