NodeJS and Jenkins - node.js

As part of the setup for building my environment for a job in Jenkins, I have checked the
Provide Node & npm bin/ folder to PATH
At the moment it defaults to Installation NodeJS
When running a job it gets to this point
$ /Users/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS/bin/npm install -g grunt-cli
but returns
env: node: No such file or directory
When manually going to the npm folder I cannot cd into it but a ls -la outputs
npm -> ../lib/node_modules/npm/bin/npm-cli.js
What is happening here, and why am I getting the error?

Related

Run Laravel Mix without a global nodejs and npm installation

I have a laravel project and I need to build styles and scripts with laravel-mix, but a testing server (Ubuntu 20.04.4) hasn't a globally installed node. Node and npm are in different folders in the system so I run commands like this:
/path/to/node /path/to/npm install
/path/to/node /path/to/npm run dev
But when I run npm run dev (this command runs laravel-mix build), I see the error:
> mazer#2.0.0 dev
> mix
/usr/bin/env: ‘node’: No such file or directory
In the package.json it looks like this:
"scripts": {
"dev": "mix"
...
}
I checked the laravel-mix package (in node_modules) and found this: #!/usr/bin/env node. The package checks the node var in this file, but there is no node var.
I don't need to change the env file, so how can I change this path or set a temporary system var? Is there any way to simulate that the variable is there?
I have one solution for this problem.
The issue regarding naming misspelling or path symlinks.
so that you need to link symlinks for nodejs with this command
ln -s /usr/bin/nodejs /usr/bin/node
or
sudo ln -s /usr/bin/nodejs /usr/bin/node
I resolved my issue with Docker, so now I run this command on git push:
docker run --rm -v /path/to/project:/var/www/html node:16.16.0-alpine npm run dev --prefix /var/www/html
Perhaps it will be useful to someone.
UPD
I found another way to resolve it, I use PATH incorrectly and for this reason it didn't work:
Wrong
I set paths to node and npm and then add it to PATH like this:
NODE_PATH="/path/to/node_folder/node"
NPM_PATH="/path/to/node_folder/npm"
PATH="${NODE_PATH}:${NPM_PATH}:$PATH"
And the system can't find npm and node anyway.
The right way
Add /path/to/node_folders (node and npm are in it) to PATH:
NODE_DIR="/path/to/node_folder"
PATH="${NODE_DIR}:$PATH"
And then, I can run just npm install and npm run dev without full paths to them.

`gulp` command doesn't work as expected on Linux

I am trying to set up the needed environment for a project I am gonna work on. I am not able to run gulp command as expected (as it is told on the getting started page of Gulp).
I am using Linux (PopOS) which is based on Ubuntu and Debian.
So, I have tried to fix it in the local project repo - which was unsuccessful.
Then I decided to create a new project directory and see whether it works. I have done these in the new project file:
$ node -v
v8.10.0
$ npm -v
5.6.0
$ npx -v
9.7.1
$ npm install --global gulp-cli
$ npm install --save-dev gulp
After all these, at the last step, when I do:
$ gulp
-bash: /usr/bin/gulp: No such file or directory
this is what I get.
However, if I do this,
$ node_modules/gulp/bin/gulp.js --version
CLI version: 2.2.0
Local version: 4.0.2
I get some result.
Does anybody see why gulp isn't getting in my binary directory? - Even though I have done the same exact steps that are presented on the official website?
This issue was about npm prefix that defines the directory where npm packages will be installed. Because the gulp binary wasn't in one of the directories that is in PATH variable bash wasn't able to find it. Here you can find details about how to fix.

Running node CLI module locally

I am having an node module which is a CLI script. The CLI uses the process.cwd() to get the current directory from which the cli script is invoked( that is important).
This works fine when I install the CLI module globally
(https://www.npmjs.com/package/reduxboilergen)
npm i -g <module>
But when I install it locally
npm i -S <module>
Then
1) The script is not invoked
2) I added a script in package.json and then if I run npm run "script_name", it is invoked but it always takes the directory from where the npm script is invoked as the process.cwd().
So if the folder structure is
root
- src
Then even if I run it inside src directory its picking up root as cwd() as the package.json is in root.
The node_module npm-run ( https://github.com/timoxley/npm-run)
solves this problem but is there any other way that you experts can think of so that I dont have to add this dependency?
The answer would be npx as of npm 5.2.0

Set directory for NPM

I'm working with git-bash on win 7. I want to develop an ember project and I am working on a thumb drive. I have installed node on my E drive and added the path to the env vars.
$ npm install -g ember-cli
C:\Users\me\AppData\Roaming\npm\ember -> C:\Users\me\AppData\Roaming\npm\node_modules\ember-cli\bin\ember
C:\Users\me\AppData\Roaming\npm\� -> C:\Users\me\AppData\Roaming\npm\node_modules\ember-cli\bin\ember
+ ember-cli#2.16.2
updated 553 packages in 89.25s
$ which npm
/e/nodejs/npm
$ which node
/e/nodejs/node
$ ember build
sh.exe": ember: command not found
So I think whats happening is that npm is installing the packages on the c drive. I need to set a folder on my e drive, to make this portable. How can I do this?
You can set this by configuring the npm prefix setting:
npm config set prefix e:\some\path\on\e
This could be done globally or on a per-project basis by modifying the project's .npmrc file.
Go to the folder with your package.json and run npm config ls to see your effective npm config.
See the npm docs for global settings

npm - set project specific default prefix/path

I would like npm ... to always run in the context of a subfolder of my project: "./assets".
When I run this command from the project root, it behaves as expected:
$ npm --prefix ./assets install
However, it does not read this from the .npmrc in the root folder.
$ echo "prefix=./assets" > .npmrc
$ npm i
# creates an empty ./node_modules folder
How can I set a set project specific default prefix for npm commands?
If you have install npm globally you can simply configure prefix to set for specific folder so that you can install other node modules to that folder. Following is the command to set prefix.
npm config set prefix /Programming/node-v0.10.31-linux-x64/
here i have configure Node in node-v0.10.31-linux-x64 this folder and node modules will be install there.
or
if you want to install node modules for specific folder individually you can user following command
npm install bower -g --prefix /Programming/node-v0.10.31-linux-x64/

Resources