serverless: command not found in ubuntu 16.04 - node.js

I am trying to set up the AWS Serverless framework in Ubuntu 16.04 LTS. I installed Node.js and have also installed Serverless using the following command: npm install -g serverless in the terminal.
But when I try to run serverless it returns an error saying serverless: command not found. Below is a screenshot for reference:

Try running,
npm config set prefix /usr/local
and then,
npm i -g serverless

If the above options are not working (due to insufficient access or sudo access), following one will definitely work as it's saving the serverless into your local.
npm install serverless --save-dev
node ./node_modules/serverless/bin/serverless deploy
Reference link - https://serverless.com/framework/docs/providers/aws/guide/services/

Was getting the same error serverless: command not found but instead of NPM was using YARN. To fix it had to execute (or better add to your ~/.bash_profile):
export PATH="$PATH:$(yarn global bin)"
then, if not already installed:
yarn global add serverless

my recomendation here is to allways install the serverless framework as a dev dependency (npm install serverless --save-dev) specially if you're working in a team where each member can have its own version of the framework. After that, you can call the framework using npm scripts. For example, you can create a new entry in the scripts section like this: "deploy" : "serverless deploy" and call it using npm run deploy.

Try with the following order
npm config set prefix /usr/local
sudo npm i -g serverless
sudo /usr/bin/node /usr/local/lib/node_modules/serverless/node_modules/tabtab/src/cli.js install --name serverless --auto

Another option, following this post, is to try npx serverless ...

Related

loopback "lb4" command is not working after successfully installation of loopback CLI using "npm i -g #loopback/cli"

I have successfully installed loopback CLI using npm i -g #loopback/cli after that I'm trying to create app using lb4 app command terminal and it shows me Command 'lb4' not found.
Only lb app works for version 3 and 2 but I want to create application compatible with loopback version 4.
I had the same problem and solved it by updating to the latest version of Node.js (10.7 as of now). Then I reinstalled the LoopBack CLI with npm i -g #loopback/cli and the lb4 app command worked just fine. Also, I was executing all the commands as admin, in case it helps.
If you're having trouble creating a global link on Windows 10 (like I did).
Consider installing in the NodeJS project folder as a work-around.
Simply execute:
npm install #looback/cli --no-save
Notes:
This will install the cli without listing it as a dependency in your package.json.
This will allow you to run lb4 app only in the root folder of project where you ran the command.
This solution is not ideal since you'll have to do this for each project. However I figured it beats having to install a new version of NodeJS just for the installer to clear some cache/configuration that got messed up over a long time-period.
Upgrade your Node.JS to version 8.9 or higher.
It's a Prerequisites.
See the doc: https://loopback.io/doc/en/lb4/Getting-started.html#prerequisites
Also some time npm installs the JS module successfully but does not add in environment variable. Find the npm folder path (in my case C:\Users\user_name\AppData\Roaming\npm) and add into class path. After adding environment variable restart the command prompt.
I was also facing same problem. But then I ran the command using sudo and it worked. sudo npm i -g #loopback/cli.
sudo update-alternatives --install /usr/bin/lb4 lb4 /opt/nodejs/node-v19.1.0/bin/lb4 0
This command will be more useful to solve this problem.
You can replace nodejs path according to your system.(/opt/nodejs/node-v19.1.0/bin)

Installing Angular CLI with npm install fails

I am new to AngularJS, just started an online course.
I am trying to install angular CLI on my computer at work running Windows 7.
I opened command line as administrator and running npm install -g #angular/cli. Installation starts and after a few minutes I get an error:
I see the notification "operation not permitted", but I am the administrator of the computer and the command line I run as administrator.
What am I doing wrong?
The same installation I did on my laptop at home and it was successful.
I am checking with our IT support about other possible causes and will appreciate any help.
This is not a duplicate of Fail to install npm package “npm ERR! errno -4048” or npm install -g angular-cli fails.
Ignoring the error and running gn -v I get the following:
Is this correct? Was Angular CLI installed?
These issues are because of the company proxy settings.
Check with your admin to get the proxy for http or https.
It will be something like this:
http_proxy = http://http.myproxy.com:8000
https_proxy = http://http.myproxy.com:8000
Replace myproxy with the name of company proxy.
Then go to the command prompt and run the following command to set the proxy. Later you can run any command like npm install -g #angular/cli to run. It will work
npm config set proxy http://http.myproxy.com:8000
npm config set https-proxy http://http.myproxy.com:8000
That fsevents library has peculiarities on Windows. So I suggest you ignore the error message and run ng -v from the command prompt to confirm you got the Angular CLI libraries installed.
You need to run the npm commands on node.js command prompt but not on windows command line.
Workaround: install git bash on windows.
As the error message suggest, you don't have some permissions to execute your command.
Depending on your system, you should run the command as an administrator.
Also, don't mix AngularJS (the first Angular framework) and Angular (also known as Angular 2, 4 and 5 now) . They are radically different in their syntax and uses.
Run below command and try installing angular cli again.
npm cache clean -f
This worked for me manytimes.

How to start the node.js application using pm2

I have installed pm2 module using the following command:
npm install pm2#latest
Then I tried to start my test application using pm2 as follows:
$ pm2 start test.js
It throws the following error:
'pm2' is not recognized as an internal or external command
Do i need to set environment variable for pm2?
You need to install PM2 globally via npm install --global pm2#latest and if you want to use the local version, try ./node_modules/.bin/pm2 start test.js.
After installing PM2, we may need to add following value to path variable under Environment Variables
C:\Users\USERNAME\AppData\Roaming\npm
After adding, reopen the command prompt.
You might installed the pm2 locally instead of global scope, this is due to missing -g parameter in your installation command.
npm install -g pm2
or
yan add -g pm2
If you tried npm install pm2 then the module will install locally to the app that you are currently developing from there you can invoke the pm2 using,
./node_modules/pm2/bin/pm2 start index.js
But it won't mostly work on windows. Try to use the global install option.
You are getting the same error after global install option then add the npm path in your environment variables.

Node npm global install of express cloud9

I am trying to install express globally in cloud 9 IDE. I run the following command -
npm install -g express
then on the bash prompt I enter -
express --version
I get unknown command error?
Can I not install stuff globally on cloud 9 ?
Niladri
You need to add environment variables to achieve that in windows some times. May be you can try that there.

Setting up StrongLoop with my node applications

I'm currently testing platforms that provide a monitoring service for nodejs application. So I found (for now) StrongLoop and AppDynamics (recently acquire nodetime).
Actually I'm testing StrongLoop service. I have followed all the steps describe in the documentation but I can't see any data on the dashboard, only the StrongLoop Demo App. Here is all the steps :
npm install -g strongloop
npm install --save strong-agent
$ slc strongops (command that create strongloop.json file)
add "require('strong-agent').profile();" line on first line of each applications (2)
restart my applications (using PM2 to manage my applications - cluster mode, AWS EC2, Ubuntu)
Any idea ?
Tank you.
My answer with links got deleted by another SO user so I'm listing the steps here.
First uninstall using this
$ npm uninstall -g strong-cli
$ npm uninstall -g loopback-sdk-angular-cli
and then install
npm install -g strongloop
You can now run slc strongops
and let us know how it goes.
I created a Linux init.d Daemon script which you can use to run your app with slc as service:
https://gist.github.com/gurdotan/23311a236fc65dc212da
Might be useful to some of you.

Resources