Jenkins cannot run npm or pm2 by itself - node.js

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

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.

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

Jenkins script quitting prematurely when using npm install on Windows

In my Jenkins job I want to build a JavaScript app using Grunt. The Jenkins build scripts creates a build directory (if it doesn't already exist), changes to that directory and runs:
npm install grunt
npm install grunt-zip
grunt --gruntfile=[something]
(Of course grunt-cli is installed globally.) When I build the job, the first statement causes Grunt and dependencies to be pulled down as expected. However, the job then terminates successfully:
Archiving artifacts
No emails were triggered.
Finished: SUCCESS
The second npm install is not run. Any idea why the script is terminating after running npm install instead of continuing to the subsequent statements?
So it turns out that npm is a batch file, not an executable, so it needs to be invoked using call from the Jenkins script:
call npm install grunt
i would recommend not using the local grunt / nodejs install, but instead getting jenkins to do this for you!
it's much easier and means there's less coupling to system specific installs and variables.
steps:
a) use nodejs jenkins plugin + get it to install nodejs on machine/grunt-cli -> Jenkins integration with Grunt
b) populate your package.json with any nodejs dependances required, eg grunt/grunt-zip etc
c) when running grunt just do a "npm update" before "grunt" command
that way your not doing explicit npm install, it's all configured from your package.json, and your build scripts will be less brittle, and your developers can use the same steps as the build server, eg "npm update;grunt" locally same as build server
For future googlers:
use command chaining for this.
This works:
npm install && npm install install grunt-zip
This wont work:
npm install
npm install grunt-zip

Resources