node.js commands on AWS elastic beanstalk ec2 server - linux

I created an elastic beanstalk node.js app on AWS, which created the EC2 and RDS server for me. I am using putty to connect to my Linux EC2 instance, which is successfully logged in.
But the following command doesn't work:
node -v
npm install express -g
node
it gives me an error:
bash: node: command not found

Node is automatically installed on your instance for elastic beanstalk. It's not in the path.
Look for node installation under /opt/elasticbeanstalk/node-install/ folder.
You shouldn't be installing modules from command line. The preferred way to install node modules on elastic beanstalk is thru package.json. Dependent modules are automatically installed on the instance by aws.

you should find out which node version is being used right now. Then you can use that in your PATH and use npm/node binary..
grep node /var/log/nodejs/nodejs.log
export PATH=$PATH:/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/

Assuming you're using Amazon Linux 3.4:
> rpm -Uvh http://download-i2.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
> sudo yum install nodejs npm --enablerepo=epel
That should do it.

You can find out where node is installed, and npm, by running ps aux | grep node. This will show you the directory it is being run out of. This is how they give you the ability to pick your version of node, by installing multiple versions. But as palanik says, no need to try to do this manually, unless you are trouble shooting. Which is the PITA on AWS, but that's another discussion.

Related

Stop EBS Linux 2 (Node.js) from trying to do npm install?

I'm trying to run a Node application on AWS Linux 2 on Elastic Beanstalk and need to install the dependencies using yarn. (My Node app causes errors if you try to use npm to install dependencies instead of yarn.)
I've already figured out how to set up a script in .platform/hooks/prebuild/ to get it to run yarn, but even though it's running the yarn installation, it still also tries to run npm install, which errors out, causing my deploy to fail.
So I need to figure out how to prevent the default npm install step from running.
(Does anyone know what file that command is run from in the AWS Linux 2 setup process? I was wondering if I could just add another script in .platform/hooks/prebuild/ that would modify that file to prevent the call to npm.)
yes, you can avoid npm install
When you deploy a node_modules directory to an Amazon Linux 2 Node.js platform version, Elastic Beanstalk assumes that you're providing your own dependency packages, and avoids installing dependencies specified in a package.json file.
source doc

Laradock - add custom npm package

It's a kind of not normal thing, but this is something, that temporarily is a solution.
I have laradock installed in a system and laravel app.
All that I'm using from laradock provides me command below
docker-compose up -d nginx mysql php-worker workspace redis
I need to add node package (https://www.npmjs.com/package/tiktok-scraper) installed globally in my docker, so I can get results by executing php code like below
exec('tiktok-scraper user username-n 3 -t json');
This needs to be available for php-fpm and php-worker level, as I need this in jobs and for endpoints, that should invoke scrape.
I know, that I'm doing wrong, but I have tried to install it within workspace like using
docker-compose exec workspace bash
npm i -g tiktok-scraper
and after this it's available in my workspace (I can run for instance tiktok-scraper --help) and it will show me the different options.
But this doesn't solve the issue, as I'm getting nothing by exec('tiktok-scraper user username-n 3 -t json'); in my laravel app.
I'm not so familiar with docker and not sure, in which dockerfile should I put something like
RUN npm i -g tiktok-scraper
Any help will be appreciated
Thanks
To execute the npm package from inside your php-worker you would need to install it in the php-worker container. But for the php exec() to have an effect on your workspace this workspace would need to be in the same container as your php-worker.

How to check which user Phusion Passenger chooses to run node.js?

What is the best practice for using Phusion Passenger with a version of node installed my nvm?
In this tutorial on using Passenger to run a Meteor app, I read:
[Y]our Meteor application is run as ... the owner of the
main.js file (when deploying a Meteor bundle), unless you configure it
otherwise. Of course you still have to make sure that each of your
applications is owned by another user.
Meteor 1.6 works with Node.js v8.8.1, so I have used nvm to install node. I created a special meteor user to run the nvm installation of node and nvm. Node was therefore installed at /home/meteor/.nvm/versions/node/v8.8.1/bin/node, and /home/meteor/.nvm/versions/node/v8.8.1/bin/ was added to the $PATH variable for my meteor user. As a result, calling node -v as the meteor user showed that v8.8.1 was installed and accessible.
I followed this tutorial to deploy my Meteor app to my server.
As the meteor user from within the bundle/programs/server directory, I ran npm install --production. I made meteor the owner of everthing inside bundle/.
I had expected that Passenger would launch node as the meteor user, and that everything would run smoothly. Instead, Passenger showed a useful alert page, apologising that "something went wrong".
To work around this, I created a symlink at /usr/bin/node to point at /home/meteor/.nvm/versions/node/v8.8.1/bin/node, and now Passenger was happy to launch the bundled app.
This suggests to me that Passenger was not running main.js as the meteor user. Or is there another reason why the meteor user was not able to see its own version of node?
The quote above suggests that it is possible to configure which user Passenger uses. How do I do that?
In a nutshell: what is the official Passenger method for working with a version of node installed by nvm?
You'll want to set the version of node to the full path to the nvm node: https://www.phusionpassenger.com/library/config/standalone/reference/#--nodejs-nodejs
As for the user-switching, you can set the log-level to 7 (https://www.phusionpassenger.com/library/config/standalone/reference/#--log-level-log_level) in order to debug that and either go through the startup logs yourself or post them here.

Unable to run packages installed using npm on VM provisioned by Chef

I provisioned my VM on AWS using Chef and installed NodeJS using the NodeJS recipe (https://github.com/redguide/nodejs). When I do a global npm install of any package, I am not able to run that package using command line. Attached the screenshot below.
My poise-javascript cookbook has node_package and javascript_execute resources to take care of all the required path munging for you.
There are two options:
1)add the /usr/local/nodejs-binary-6.3.0/bin/ to PATH variable.
Or
2)Run /usr/local/nodejs-binary-6.3.0/bin/http-server.
The npm package binaries are not added to path by default. I would prefer option 2 to keep the path unpolluted

Issues with installing nodeJS on a shared hosting plan

Here are the steps I am following:
First, I login to my account using SSH.
Then, I install nvm using
wget -qO- https://cdn.rawgit.com/creationix/nvm/master/install.sh | bash
Then, I restart the shell
Then, I install node using
nvm install stable
But, when I check for the version of the node using the following, it says 'command not found'
node --version
If it helps, here are other things I tried:
nvm list
Also, here are the contents of the .nvm folder (which is inside the root folder):
I suppose N/A indicates that node is not available.
To sum it up, is it possible at all to use node.js on a shared hosting plan? If, yes, what can I do to make it work?
PS: I have been getting suggestions to use other plans like Heroku etc. Although, I have already invested a lot in this shared hosting plan (on GoDaddy), so I would really like if I can host nodeJS applications here.
PPS: I am new to programming, so please bear with any ignorance.
Try installing node like this
nvm install node
Then, crucially
nvm alias default node
Now running
node -v
Should display correctly
First of all shared server wont allow you to install anything on their server.
If you can able to install node on your shared server then you are pretty lucky.
To run node --version command, the node command should be in your path. On shared server, it might not be allowed.
So I think you need to check with full path like `/usr/bin/node --version'
(check your installation path)

Resources