Can't run a specific version of node on openshift - node.js

I am following the steps described in this repository but I can't seem to make it work. When I look into my env file the nodejs version is still .6.20
My node js version file is the default one, so the node version .8.9 should be running. Any idea why this is happening?
My marker file:
0.8.9
Debug output when I try to start my application
==> nodejs/logs/node.log <==
npm ERR! node -v v0.6.20
npm ERR! npm -v 1.1.37
npm ERR! code ELIFECYCLE
npm ERR! message application-name#0.0.1 start: `node server.js`
npm ERR! message `sh "-c" "node server.js"` failed with 1
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /var/lib/openshift/51ba8386e0b8cd2873000002/app-root/runtime/repo/npm- debug.log
npm ERR! not ok code undefined
npm ERR! not ok code 1
Just for the sake of completeness. My package.json file
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "3.2.5",
"mustache": "*",
"request" : "*",
"buildify":"*",
"cheerio" : "*",
"slugs" : "*",
"to-markdown":"*",
"consolidate":"*"
}
}
The app runs locally just fine.

I like this version of the nodejs starter code better: https://github.com/ryanj/nodejs-custom-version-openshift
It contains a newer version of the .openshift application build hooks for nodejs. It will read the Marker file, but also has support for reading directly from your package.json file's engines attribute to compile your Nodejs runtime.
"engines": {
"node": ">= 0.10.0",
"npm": ">= 1.0.0"
},
I'm hoping to get this merged in as the default .openshift folder content for all nodejs apps on OpenShift.
You'll also want to make sure that you are binding to the NEW environment variables: OPENSHIFT_NODEJS_IP and OPENSHIFT_NODEJS_PORT. These were recently renamed.
I usually add something like this to my application code, allowing it to run anywhere:
var ip_addr = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
var port = process.env.OPENSHIFT_NODEJS_PORT || '8080';
OpenShift currently shows you the output from npm start, which may not reveal all of your application's output. For additional debugging info, you could try starting your app manually:
First, stop your app from the command line: rhc app stop APP_NAME
Then, connect to your application gear / container rhc ssh APP_NAME
cd $OPENSHIFT_REPO_DIR
and manually run whatever command is defined within your package.json file's scripts.start attribute.
Hopefully that gives you a bit more visibility into what is going on.

Maybe this will help. There are subtle differences. See also the comments.
https://www.openshift.com/blogs/any-version-of-nodejs-you-want-in-the-cloud-openshift-does-it-paas-style

Did you see anything like this in your "git push" output?
remote: - Checking to see if Node.js version 0.8.9 is installed ...
remote: - Downloading and extracting http://nodejs.org/dist/v0.8.9/node-v0.8.9-linux-x64.tar.gz ...
remote: % Total % Received % Xferd Average Speed Time Time Time Current
remote: Dload Upload Total Spent Left Speed
remote: 100 4578k 100 4578k 0 0 31.4M 0 --:--:-- --:--:-- --:--:-- 33.8M
and towards the bottom of the bottom, something like:
remote: - Using Node.js version 0.8.9, checking app URI ...
remote: - test URI = http://mynode-sannam.rhcloud.com/env
remote: - Version from test URI =
remote:
remote: - Checking to see if Node.js version 0.8.9 is installed ...
I tried the same instructions and it seems to have worked. Check my env here: http://mynode-sannam.rhcloud.com/env
Please redo your steps one more time.

I had the same problem and on the beginning i wasn't able to solve it using source code from https://github.com/ryanj/nodejs-custom-version-openshift, but reading the push output I noticed some permission problems.
So for other people that is having the same issue, just go into:
cd .openshift\action_hooks
and run this command:
git update-index --chmod=+x *
It gives the permissions to run commands that upgrades node version

Related

How to increase NodeJS heap (--max-old-space-size) in Bitbucket Pipelines for Typescript/Webpack?

I am running into memory issues during the webpack packaging step in a serverless/TypeScript project.
I have tried:
'increase-memory-limit' npm package to no avail
Calling the following command from an npm run script
Calling the following command directly through bitbucket-pipelines.yml.
node --max-old-space-size=4096 ./node_modules/.bin/serverless deploy
It works fine locally with this command, but in Bitbucket pipelines I get the following output:
Serverless: Bundling with Webpack...
internal/child_process.js:323
throw errnoException(err, 'spawn');
^
Error: spawn ENOMEM
at _errnoException (util.js:1022:11)
at ChildProcess.spawn (internal/child_process.js:323:11)
at exports.spawn (child_process.js:502:9)
at Object.exports.fork (child_process.js:103:10)
at fork (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/fork.js:17:36)
at Farm.startChild (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:106:16)
at Farm.processQueue (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:279:10)
at Farm.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:97:21)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! platform-state-machine-import#0.0.2 deploy: `node --max-old-space-size=4096 ./node_modules/.bin/serverless deploy "--stage" "feattsify" "--region" "us-east-1"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the platform-state-machine-import#0.0.2 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-02-07T22_37_25_150Z-debug.log
I've done a lot of googling and searching here to try to find if Bitbucket has some kind of env. variable you can set for runtime args, etc., but can't seem to find anything that doesn't tie back into the aforementioned NPM package.
I encountered a similar issue some time ago in some Jenkins build tasks.
You might be able to solve it using the NODE_OPTION environment variable:
NODE_OPTIONS=--max_old_space_size=4096
From your error stacktrace, it looks like new node processes are beeing spawned.
If you can set this environment variable, it will be used by node to pass arguments to any new processes, and so to the spawned processes that run out of memory here.
https://nodejs.org/dist/latest-v8.x/docs/api/cli.html#cli_node_options_options
Defining a fixed amouth of memory could be tricky, since you will not use the full memory available on the runner machine.
I wrote a code, to get the total memory on the runner machine, deduct 400mb (to other server resources), and assign it as node memory limit.
FREE=$(free -m);
echo "FREE: ${FREE}"
FREE_FINAL=$(echo "$FREE" | grep -F Mem: | grep -o "[0-9]*" | grep -o -m1 "^[0-9]*")
echo "FREE_FINAL: ${FREE_FINAL}"
MEM_LIMIT=$(($FREE_FINAL-400))
echo "MEM_LIMIT: ${MEM_LIMIT}"
echo " - "
export MEMORY_LIMIT="${MEM_LIMIT:=3500}";
export NODE_OPTIONS="--max-old-space-size=${MEMORY_LIMIT}"
echo "NODE_OPTIONS: ${NODE_OPTIONS}"
You can adapt to your case and use the maximum memory to your script, but respect the limit as well.
If you use docker, it can be added to an entrypoint.sh file (that will run on build time, but on each docker start as well).
Increase it from your start command e.g
node --max-old-space-size=8192 server.js
There ended up being two workarounds for this issue. The ENOMEM error was appearing first because I needed more memory for the Node process, and second because the memory I was allotting to the Node process exceeded that which was available in the Bitbucket environment (default 4gb).
Option 1:
Using any of the other answers' options AND ensuring the Bitbucket pipeline environment has enough memory - for me, that meant cranking the size to 2x (see this link).
Option 2:
Adding the 'transpileOnly' flag to your webpack.config.js file, using ts-loader as your transpiler. This skips type-checking and saves memory at package/deploy time. WARNING: You still should type-check your project on build. For me, this meant running tsc before packaging/deploying.
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true
}
},
],

Failed exitCode=-4071

I am following this guide. Having problem deploying to azure.
https://learn.microsoft.com/en-us/azure/app-service-web/app-service-web-nodejs-sails#step-3-configure-and-deploy-your-sailsjs-app
Full Error
remote: Failed exitCode=-4071, command="D:\Program Files (x86)\nodejs\6.9.1\node.exe" "D:\Program Files (x86)\npm\3.10.8\node_modules\npm\bin\npm-cli.js" install --production
also
remote: npm ERR! EINVAL: invalid argument, rename 'D:\home\site\wwwroot\node_modules\.staging\spdx-license-ids-3f30671f' -> 'D:\home\site\wwwroot\node_modules\sails-hook-grunt\node_modules\grunt-contrib-cssmin\node_modules\maxmin\node_modules\pretty-bytes\node_modules\meow\node_modules\normalize-package-data\node_modules\validate-npm-package-license\node_modules\spdx-correct\node_modules\spdx-license-ids'
Thanks
I do a demo following the tutorials that you mentioned. It works correctly on my side. I used node.js v7.9 locally. If it is possible, please have a try to update the node.js version to latest locally. The following is my details steps.
1.Following the document to install Sails and create a demo project
$npm install sails -g
$sails new test-sails-project
2.go to localhost:1337 to see your brand new homepage
$ cd test-sails-project
$ sails lift
We can check that it works correctly in the local
4.Following the document step by step
a.Add iisnode.yml file with the following code in the root directory
loggingEnabled: true
logDirectory: iisnode
b.set port and hookTimeout in the config/env/production.js
module.exports = {
// Use process.env.port to handle web requests to the default HTTP port
port: process.env.port,
// Increase hooks timout to 30 seconds
// This avoids the Sails.js error documented at https://github.com/balderdashy/sails/issues/2691
hookTimeout: 30000,
...
};
c.hardcode the Node.js version you want to use. In package.json
"engines": {
"node": "6.9.1"
},
5.Create a Azure WebApp on the Azure portal and get the profile.
6.Push the code to the Git remote and check from the Azure portal.

Running AtlasBoard on Azure Web App with iisnode

I´m trying to run AtlasBoard in an Azure Web App, but can´t get it to work. I have created a new board using the "Get started in 30 seconds" steps and the demo board runs fine when I start it locally. It works both by starting it with atlasboard start 3333or if I run node start.
I´ve added the node_modules directory to .gitignore.
I´m using git deployment on Azure and this seems to work fine. The deployment log also shows that the npm modules are installed.
This is the last ouput from the deployment:
Using start-up script start.js from package.json.
Generated web.config.
The iisnode.yml file explicitly sets nodeProcessCommandLine. Automatic node.js version selection is turned off.
Selected npm version 3.5.1
npm WARN Invalid name: "HRMTS AtlasBoard"
npm WARN wwwroot No description
npm WARN wwwroot No repository field.
npm WARN wwwroot No README data
npm WARN wwwroot No license field.
Finished successfully.
However, the app doesn´t seem to start and when I look at the log message in the Kudu console, I get this:
Error: error installing D:\home\site\wwwroot\packages\demo
at process.<anonymous> (D:\Program Files (x86)\iisnode\interceptor.js:73:106)
at emitOne (events.js:96:13)
at process.emit (events.js:188:7)
at process._fatalException (node.js:267:26)
Does anyone have a clue about what´s wrong here?
If you are using the repo of the demo application at https://bitbucket.org/atlassian/atlasboard/src to test on Azure, there several additional modifications we need do to make the test run on Azure Web Apps.
First of all, assume you have successfully deploy the application to Azure, and it failed when start running the application. Then you can leverage Kudu console site or Visual Studio Online extension (refer to the answer of How to install composer on app service? for how to enable extensions of Azure Web Apps) to check the error log at D:\home\site\wwwroot\packages\demo\npm-debug.log.
There are similar errors:
155 error node -v v0.6.20
156 error npm -v 1.1.37
157 error message SSL Error: CERT_UNTRUSTED
It seems that the atlasboard runs command with very low node version on Azure. We can manually modify the dependent scripts to bypass the errors.
If you get error during deployment, you should modify the npm version in package.json before deployment, for example:
"engines": {
"npm": ">2.0.0",
"node": ">=0.10"
},
After deployment:
check and modify the port in the start.js in the root directory:
atlasboard({port: process.env.port||3000 , install: true},
function (err) {
if (err) {
throw err;
}
});
modify the install function in D:\home\site\wwwroot\node_modules\atlasboard\lib\package-dependency-manager.js to use a higher npm version and remove --production param, e.g :
...
var npmCommand = isWindows ? "D:\\Program Files (x86)\\npm\\3.5.1\\npm.cmd" : "npm";
executeCommand(npmCommand, ["install", pathPackageJson], function(err, code){
...
})
Then restart your website.
Any further concern, please feel free to let me know.

Amazon Elastic Beanstalk npm cant find package.json

I'm very new with amazon web services, and I am trying to set up a node.js app on their elastic beanstalk. I set up the instance and uploaded/deployed the site, but while the health is "Ok" the node.js logs show this repeated about 30 times:
npm ERR! enoent ENOENT: no such file or directory, open '/var/app/current/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /var/app/current/npm-debug.log
npm ERR! Linux 4.1.13-19.31.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/npm" "start"
npm ERR! node v4.2.3
npm ERR! npm v2.14.7
npm ERR! path /var/app/current/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
The problem is that my package.json does exist because I generated one with npm init. Any ideas on why it cant be found? Here is the package.json
{
"name": "testwebsite",
"version": "0.0.1",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"body-parser": "^1.13.3",
"express": "^4.13.3",
"express-session": "~1.0.0",
"socket.io": "^1.3.7"
},
"description": "my website",
"author": "Matt",
"engines": {
"node": ">=0.10.0"
},
"main": "server.js",
"devDependencies": {},
"license": "ISC"
}
From an official AWS thread[1], it appears (and this was my problem) that you might be zipping the top-level directory rather than zipping the source itself.
For example, you may have all of your files in a folder called "Project". Rather than zipping "Project", you should zip and upload the contents of "Project".
[1] https://forums.aws.amazon.com/thread.jspa?messageID=476022
I had a problem the same as - or very similar to this, and it was caused the fact that my code was listening to a custom port, instead of the one that Elastic Beanstalk sets as an environment variable (8081).
I fixed this setting in the port near top of my app.js or server.js file, just after I create the express app. For example:
var app = express();
app.set('port', (process.env.PORT || 5000)); // 5000 was my original port
Then using this port in the app.listen method instead of my own custom port number:
app.listen(app.get('port'), function () {
console.log('Server has started! http://localhost:' + app.get('port') + '/');
});
More details here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#nodejs-platform-proxy
I was having these odd error on AWS EB as well. I was generally deploying using the CLI.
couple things to try.
make sure the package.json is not in your .gitignore file, to ensure it is being committed to your repository. EB uses the git commit history to decide what to zip and send. If that isnt included it is not on the AWS servers
i was using the t2.nano instance (512MB space) option for EC and that seemed to be an issue because I had a lot of modules in my package.json. Wasnt sure if that was the root issue of my woes but my error messages changed when I upgraded to an instance that had at least 1GB of space.
hope this helps
I was having something similar whereby the elastic beanstalk deploy failed when using the eb cli. I realized that the elastic beanstalk config files had inadvertently been added to my .gitignore file causing the deploy to fail.
I had trouble with the zipping, etc. I recommend using CodePipeline and linking it to your github or AWS codecommit. Then, skip the build stage, and for the deploy stage click elastic beanstalk.
You will have to pause the process and open a new tab and go to EB and create a new environment. Make sure you click nodeJS in this example. Make sure you choose "sample code" so that AWS can set it up with their template. Once the EB is finished building you should have a link to the template that is functional.
Then you can go back to your CodePipeline tab and click on Elastic Beanstalk for deployment and you should find the EB you just made.
I recommend this process because it will automatically update every time you do a git change. This is better than zipping a file, etc.

Is it possible to access npm config settings from a node package's `bin` command?

I want to add some default configuration into a shell tool that the user can override using npm config. It looks like this is possible but this only works for npm scripts not my package's binary as specified by "bin" below.
Package.json
{
"name": "tmp",
"scripts": {
"test": "node index.js"
},
"bin" : {
"tmp" : "index.js"
},
"config": {
"foo" : 123
}
}
index.js
#!/usr/bin/env node
console.log(process.env.npm_package_config_foo);
My attempts
calling binary
setup for this is running npm link in the package to make a global link to that package
$ tmp
undefined
passing script to node
$ node ./index.js
undefined
calling as npm script ⫸ only this one works
$ npm test
> tmp# test /private/tmp
> node index.js
123
Question
How can I access these config values in a way that's overridable by the user like npm config allows? (To be clear I want to do it the npm config way; I know there are other ways to skin this particular cat.)
You can use a package called npm-conf with documentation at https://github.com/kevva/npm-conf.
First you need to install it:
npm install --save npm-conf
Usage is as follows:
const npmConf = require('npm-conf');
const conf = npmConf();
conf.get('prefix')
//=> //=> /Users/unicorn/.npm-packages
conf.get('registry')
//=> https://registry.npmjs.org/
If you want to get a list of all available NPM configuration options:
npm config list -l

Resources