pm2: command not found after npm -g - amazon-web-services

I have installed pm2 with the following command
npm install pm2#latest -g
This worked OK, and I am now running production services used pm2.
I exited the shell ( AWS ) and now if I try pm2 list I get error:-
pm2: command not found
I think the issue might be that I SHOULD have run sudo npm install pm2#latest -g
From previous stackoverflow answers I can see this is the suggested approach, but my question is this.....
If I now run sudo npm install pm2#latest -g will this impact my currently running pm2 services ?
Thanks

I belive the problem is that you haven't add the npm global directory to your sell path
Check this guide:
https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
TLDR:
What you want to do is to get your npm prefix dir by executing
npm config get prefix
then your pm2 is in <YOUR_NPM_PREFIX>/bin/pm2
To add your npm global user dir to your shell PATH, you can put this commad
export PATH="$PATH:<YOUR_NPM_PREFIX>/bin"
in your .bashrc, don't forget to re-login your shell or source ~/.bashrc if you're using bash

Related

Setting PATH environment variable in Macbook M1 for AWS amplify error

I have just installed amplify by doing npm install -g #aws-amplify/cli
Now I am trying to amplify configure but it is giving me an error: zsh: permission denied: amplify
So I used sudo in front of it, entered my password, but this time it says amplify: command not found
I have a feeling it is likely to do with my PATH environment variable. But I am worried because I am not too familiar with this stuff. All I know is I can see that some of my global packages are installed in usr -> local -> lib -> node_modules and some are installed in opt -> homebrew -> bin
I tried putting this command in my zshrc: export PATH="$PATH:/opt/homebrew/bin/" and it does not work. I realized that my /opt/homebrew/bin is actually located in macintoshHD/opt/homebrew/bin. This means I have to go up twice, because $PATH is my userName. so I tried putting export PATH=$PATH:/../../opt/homebrew/bin/ but it still does not work.....
Could someone please help me with this? Just give me the commands for setting my PATH env variable to be correct, and I will do it. Thanks in advance!
My guess is your first install despite it's a global install finished with some errors.
try installing it using sudo :
sudo npm install -g #aws-amplify/cli
and change owner of the local directory :
sudo "cd ~youruser && chown youruser ~/.amplify"

Receiving could not find “htmlextra” reporter when i run it on my local (Linux) neman html report generation

I am receiving the below message when I run Newman run the command with parameter -r HTML extra. Where I have already installed HTML extra using -g (globally). But when I create a Newman .js file I am able to execute. Please advise what might have gone wrong.
"
Newman: could not find "htmlextra" reporter
ensure that the reporter is installed in the same directory as newman
please install reporter using npm
"
Install newman & htmlextra from the node.js command prompt using below commands:
npm install -g newman
npm install -g newman-reporter-htmlextra
After successful installation, run the below command
newman run ""Reqres.postman_collection.json" --reporters=cli,htmlextra
Single or double quotation marks ('',"") must be added in the --reporters args in order to take both args and run on cli and export HTML report at the same time.
newman run collectionName.json --reporters='cli,htmlextra'

Ionic CLI not uninstalling

This is related to my previous question here which was never resolved. I am trying to fix the problem by doing a fresh reinstall of Ionic.
I first tried uninstalling Ionic with sudo npm uninstall -g ionic, and it completes with no errors, but doing ionic -v still outputs 2.1.1, so obviously it didn't really get uninstalled. After that I tried sudo npm install -g ionic#latest, and my problem still persists.
What is even weirder is what happened when I tried to create a new project from scratch to test it. I did ionic start test --v2 on my Ubuntu machine, and doing ionic serve still does the same thing that I stated in my previous question.
npm uninstall -g ionic
npm uninstall -g #ionic/cli
finally i was able to uninstall with this...
I had the same issue for resolving this
Run npm uninstall -g ionic
Go to the location "/usr/local/bin/"
Delete Ionic File
Close terminal
Open new terminal and run "npm uninstall -g ionic"
Now run "ionic -v"
This probably happens due to multiple installations of ionic in your machine, more so this happens on windows.
Run:
"where ionic" in your command prompt
if it does not work try :
"which ionic" !! (probably linux)
This will give you the location of your installed ionic, in windows its mostly ..Local\AppData\Roaming.. somewhere.
Go to that location delete ionic and ionic.cmd file there.
Run: ionic -v now, make sure it gives you an error.
Be Happy if you see error.
run: npm install ionic#latest -g now
Run: ionic -v, make sure you see your latest ionic version there.
Be more happy now.
Uninstall cordova and ionic.
npm uninstall -g cordova
npm uninstall -g ionic
Then check to make sure you have the right version:
ionic -v
Use this command please
npm uninstall -g #ionic/cli
What is your node and npm versions ?
Please update latest node js (https://nodejs.org/en/download/current/)
then check that
node -v
npm -v
Node version must be v8.5.0 (includes npm 5.3.0) and then
sudo npm uninstall -g ionic
sudo npm cache clean --force
sudo npm install ionic
check the ionic version
ionic -v
version will be ^3.10.1. If everything is ok you can use new project command as given below
ionic start --list
you can see what kind of project types here as an example
ionic start blank
You can try running the command as below, it worked for me:
sudo npm uninstall -g #ionic/cli
If you are checking the ionic version inside project folder then
try to remove the ionic cli without -g option. It may be possible that you have installed local version of ionic inside project.
If you're using nvm, remember to delete ionic from where ionic. I deleted it via nvm uninstall {{version}}.

How do I make bower install work with aws.push?

As a starting point to making my own app that uses meanjs, I went to the meanjs website and used their yeomen generator to create the template/sample app. Following the instructions getting the sample application running out of the box on my local desktop machine worked within minutes. To complete the exercise I tried to deploy the sample app to an AWS/EC2 instance before making any changes to it. I have used the command line deployment tools in the past and liked it. Also it is nice how now you can just select an EC2 Linux instance with node and npm already installed and ready.
After checking the sample into git, I run "git aws.push" to deploy the app.
The problem is in the package.json the line:
"postinstall": "bower install --config.interactive=false"
In the eb-activity.log:
npm WARN cannot run in wd meansample#0.0.1 bower install --config.interactive=false (wd=/tmp/deployment/application)
The result is that AngularJS ends up not getting installed in /public/lib.
First thing I tried was giving the full path in the package.json file: node_modules/bower/bin/bower. This didn't help and results in the same error. Also noting that other commands like "grunt" don't need the full path specified in the package.json and they work.
I don't understand enough of the black box magic that aws.push does to understand why this error is happening. For example what user does it run as? What permissions does that user have? what options if any does it use when it runs npm install?
I did figure out a work-around, but it adds a lot of extra steps that shouldn't be required if aws.push was able to run bower install directly. Basically I can manually run the bower install in the ssh client connected to my EC2 instance, set the owner/group on the installed files, and restart the server.
Work-around steps:
1) On local command prompt run git aws.push. Wait for unsuccessfully deployment to finish.
2) Connect ssh client to EC2 instance. From the command prompt:
cd /var/app/current
/* NOTE: if I don't use sudo the ec2user I am logged in as does not have permission to create /public/lib needed to install AngularJS into*/
sudo node_modules/bower/bin/bower install --config.interactive=false --allow-root
/* NOTE: just changing the owner and group to match the same as the other files that aws.push deployed */
sudo chown -R nodejs public/lib
sudo chgrp -R nodejs public/lib
From AWS dashboard, select the correct EC2 instance, Action = Restart App Server(s)
Now AngularJS is install and the sample app works.
How do I eliminate the extra steps and make it so aws.push can do the bower install successfully?
I have experienced the same problem when trying to publish my nodejs app in a private server running CentOs using root user. The same error is fired by "postinstall": "./node_modules/bower/bin/bower install" in my package.json file so the only solution that was working for me is to use both options to avoid the error:
1: use --allow-root option for bower install command
"postinstall": "./node_modules/bower/bin/bower --allow-root install"
2: use --unsafe-perm option for npm install command
npm install --unsafe-perm

Loopback lb-ng (LoopBack Angular SDK command-line tool) not working

I'm going through the tutorials of http://docs.strongloop.com, and I've reached http://docs.strongloop.com/display/public/LB/Add+a+client+app.
Yet when I execute 'lb-ng ../server/server.js js/lb-services.js' I get an error: Cannot find module 'loopback'.
Any help would be appreciated!
For the new version of loopback you need to install lb-ng command with this line of command
sudo npm install -g loopback-sdk-angular-cli
also try to be in the client folder make sure that you have js directory in client directory then execute these lb-ng commad
lb-ng ../server/server.js js/lb-services.js
it will work
:)
did you npm install your dependencies? check and see if you have a node_modules dir in your project root.
if you're using a newer version of node, try uninstalling node and reinstalling an LTS version.
npm uninstall -g strongloop
npm cache clear
npm install -g strongloop
This is how I fixed this problem for me.
install strong loop and then run lb-ng command this is how i fixed this problem