npm: command not found on amazon ec2 (even though its installed) - node.js

We installed NPM and created an AMI
The elastic beanstalk uses that AMI to create an EC2
The Procfile calls a shell script with the content pasted below.
I am getting the error - npm : command not found (when i use the command npm manually, it works, only fails during beanstalk deploy)
Also used the full path for npm(home/ec2-user/.nvm/versions/node/v11.6.0/bin/npm), which results in permission denied
I know its just a minor thing I am missing here, already spent few hours on this.
I tried sourcing my bash profile, which also results in permission denied.
#!/usr/bin/env bash
npm install
npm install -g serve
npm run build
nohup serve -s build > orgweb.log &

Not sure if it is just a typo or did you use this exact full path
home/ec2-user/.nvm/versions/node/v11.6.0/bin/npm
But if you did, there needs to be a slash before home, as in
/home/ec2-user/.nvm/versions/node/v11.6.0/bin/npm

Related

Why can't install npm to create package.json on AWS EC2?

I'm trying use EC2 to execute command npm install will get bellow error.
(Node.js had already install)
Dose anybody know why?
Is that the reason that I execute this command chmod 400 before login EC2 by ssh?
chmod 400 seems only could read, isn't it?
npm install only works if there is an existing package.json file. Your ls command shows that the directory is empty.
If you want to create your initial package.json file, you want to use the command npm init and answer the questions.

NPM run scripts aren't able to call `node`

Quick Summary
This is not a duplicate of the linked question, the issue there was a typo, this isn't isn't a typo.
I can run node in my bash terminal fine. If I try and run node inside an NPM script in that same bash terminal, then I get the error 'node' is not recognized as an internal or external command
Original Question
I'm having issues running npm install in one of my projects currently, but to be able to simplify all of the moving parts, I've created an NPM script in my package.json file, simply calling node nodetest.js.
The content of nodetest.js is as follows:
console.log('Node Test Success!');
On the command line, I can call node nodetest.js, and it will output the console log as expected.
If I call npm run nodetest, I get the error saying 'node' is not recognized as an internal or external command
Inside the same command line, I have access to node (/c/Program Files/nodejs/node), npm (/c/Program Files/nodejs/npm), and even npx (/c/Program Files/nodejs/npx)
Node is set in my PATH variable, and I've even added it to .bashrc.
What else could possibly be the problem?
Edit: I neglected to detail my system
Windows 10
Using Git Bash inside ConEmu
Node version 10.1.0
NPM version 6.0.0
Edit 2: Some further curiosities
If I change my NPM script to be "nodetest": "\"/c/Program Files/nodejs/node.exe\" nodetest.js", and then run npm run nodetest, I get an error in the output:
> "/c/Program Files/nodejs/node.exe" nodetest.js
The system cannot find the path specified.
BUT, if I copy that command exactly, and run it directly on the command line, it will work perfectly!

What is the 'npm' command and how can I use it?

What is npm?
Whenever I browse through some project they ask me to run npm command, something like this
npm install -g node-windows
I went through some blog posts to learn about npm and I installed Node.js. However, when I run the above code in Node.js, I get the following errors:
When I browsed further, I came to know that the windows user can run the command from the cmd prompt window, but when I do that I get some output like this:
Which just generate a text file nothing else.
My questions:
How can I get started with the AngularJS2?
How can I run an npm command?
Do I require a command prompt to run the npm command (in Windows), or I can just use Node.js?
When I use the command npm install in my command prompt, I get the following output:
How to get started with the angularJS2
Follow this link and set up the project by following instructions
How to run a npm command
npm stands for Node Package Manager, and therefore you need Node.js installed before you can run npm commands.
Follow this and install the latest version. And restart the command prompt.
Do I require a command prompt to run npm commands (in Windows), or can I just use Node.js?
Yes, you need to run npm commands from the command line (in Windows).
E.g., npm install
You get the warning because there is no package.json file present where you are running the command.
ENOENT stands for Error NO ENTrey
Navigate to the project folder using the following command and then run npm install
cd <projectpath>
The AngularJS 2 website has everything you need to be covered. Their quickstart guide alongside with the quickseed zip file helps a lot.
But, in case you missed some points:
yes, you will need npm/NodeJS. So, download the latest distribution and have a clean installation of it.
you can execute the npm command with its parameters from within the Windows cmd.
the quickseed ZIP file contains all the files you need to see a live and quick example running locally. Unzip it on your workplace and navigate to it using the windows cmd. When inside the root folder of the unzipped package, execute npm install and right after it npm start.
Take the learning path. Step by step, all your questions will be answered.
You need to use an admin prompt for global installation (-g).

Jenkins cannot run npm or pm2 by itself

So I have a Jenkins CI setup on an EC2 server. I have nodejs and npm installed. Weirdly, Jenkins can access them via the command line if I do something like:
sudo -u jenkins node -v
However, Jenkins cannot access them inside an actual build runtime, and I get the following errors:
npm: command not found
pm2: command not found
npm is definitely installed, and ec2-user/root users can access it. What PATH do I have to change so that Jenkins can access it too?
I think that if you use the nodejs plugin it will be easier to manage your node and npm in this box. Also, this plugin allows installing some global modules that possibly you will need to build your project:
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

Running node apps with CodeDeploy

I am using Codeship as my CI tool, I integrate it with AWS CodeDeploy service. The procedure is perfect until my appspec.yml file calls my script to run the node app. Even though I have npm, node, bower and grunt installed I get command not found errors.
I would try editing your start_server.sh and adding npm and node to the $PATH environment variable or put that path directly in the command itself.
So instead of
npm install
Try
/usr/local/bin/npm install
That might not be where your npm lives but if you need to find out just do which npm
Perform the below steps:
which node
sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/node (output of above step) /usr/bin/node
which npm
sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/npm (output of above step) /usr/bin/npm
and try to use it via /usr/bin/npm install
I hope this will help you!!
For people who still might run into the same problem.
Check your appspec.yml file and look at the destination, it should contain something like /home/ec2-user....
in this case we need to make sure code deploy agent runs with that user profile (ec2-user). Check this link for steps to to make code deploy to run with your user profile

Resources