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

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.

Related

katacoda command not found

I'm trying to install the katacoda client. I used NPM to install it:
npm install -g katacoda-cli
The installation was successful but when I'm trying to run the katacoda help I've got the following error: command not found: katacoda. NPM installed katacoda here: /usr/local/Cellar/node/10.7.0/lib/node_modules/katacoda-cli. If I run the following: /usr/local/Cellar/node/10.7.0/lib/node_modules/katacoda-cli/bin/run help katacoda is executed correctly. I guess my problem is coming from my $PATH, which is set like this: export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
You can go to one of the directories, say /usr/local/bin, and then run ln -s /usr/local/Cellar/node/10.7.0/lib/node_modules/katacoda-cli/bin/run katacoda. Then you should be able to run katacoda directly. If you don't have permissions to do so in /usr/local/bin, choose another directory where you have permissions, do the same and add the directory to your $PATH

npm: command not found on amazon ec2 (even though its installed)

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

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).

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

NodeJS and npm without sudo on CentOS

On my box I have the Node and NPM binaries installed under /opt/node/bin. And the path is added properly.
node -v
and
npm -v
work fine. When I create a file and run it with node all works as expected. However, when I run:
npm init
the program fails to write package.json because it does not have write permission. I use:
sudo npm init
I get a file with owner and group of 0 0 and so any regular users cannot modify this file. I don't want to have to chown every file node/npm generates.
Is there way to get node/npm to run as a user in the same group as my other users and have write permissions to the same directories?
You could simply chown your /opt/ directory and future calls to npm init will be owned by you. Better yet, work in your /home folder and make sure npm and node are in your $PATH. This way you don't need to worry about permissions for initializing a new node module. You will, however, need to use sudo to install packages globally. This is bad practice according to the maintainer of Nodejs:
http://howtonode.org/introduction-to-npm
I would follow along with his setup there. As he mentions, its very dangerous to give root access to a package manager.

Resources