Updating Nodejs version in Elastic Beanstalk - node.js

We are having some problems with the node version in production, so we changed the version required in the package.json from 0.10.0 to 6.2.2..
"engines": {
"node": ">= 6.2.2"
}
However in Elastic Beanstalk, when new instances are created they appear with node version of 0.10.0. How can we update the version in Elastic Beanstalk so the new instances created have the required version placed in package.json?
Thank you very much.

Verifying the version is supported
Most newer Beanstalk platforms have up to 6.2.2 for Node.js so if your platform version is up to date you should have it (current platform version for Node.js is v2.1.3).
If you do not want to update your current platform you can verify which versions are valid using the AWS CLI:
aws elasticbeanstalk describe-configuration-options --solution-stack-name "64bit Amazon Linux 2016.03 v2.1.3 running Node.js" --options "OptionName=NodeVersion, Namespace=aws:elasticbeanstalk:container:nodejs"
Which should return something like:
{
"Options": [
{
"Name": "NodeVersion",
"UserDefined": false,
"DefaultValue": "4.4.6",
"ChangeSeverity": "RestartApplicationServer",
"Namespace": "aws:elasticbeanstalk:container:nodejs",
"ValueType": "Scalar",
"ValueOptions": [
"0.8.28",
"0.10.46",
"0.12.15",
"4.4.6",
"5.12.0",
"6.2.2"
]
}
],
"SolutionStackName": "64bit Amazon Linux 2016.03 v2.1.3 running Node.js"
}
Making it work
In order for your application to start up with correct Node version you will have to set the option setting for the specific version. This can be done multiple ways.
Web UI
Navigate to the Configuration tab for your environment and then into the Software Configuration panel to change the Node version setting. Click apply when you are finished to deploy the changes to your environment.
AWS CLI
You can update your environment with the correct option setting via the command line interface.
aws elasticbeanstalk update-environment --environment-name yourEnvName --option-settings "OptionName=NodeVersion, Namespace=aws:elasticbeanstalk:container:nodejs, Value=6.2.2"
Here are some additional option settings specific to the Node.js platform.

Related

pm2+ not showing versioning when using ecosystem file

I'm using PM2+ to manage my NodeJS deployments.
Usually, when I deploy an application with pm2 start src/app.js, I get details about versioning like in the screenshot below. However, when I deploy using an ecosystem file I only get N/A:
PM2 normally extracts this information directly using vizion.
But since it didn't work with the ecosystem file, I specified the GitHub repository directly just like the documentation stated.
This is my current pm2-services.json ecosystem-file:
{
"apps": [
{
"name": "my-node-app",
"cwd": "./my-node-app-repo-folder",
"script": "src/app.js",
"env": {
"NODE_ENV": "production"
},
"repo": "https://github.com/MyUserName/MyNodeAppRepo.git",
"ref": "origin/master"
}
]
}
For the ref field, I also tried putting refs/remotes/origin/master, remotes/origin/master and master.
Sadly none of them worked (I made sure they are correct using git show-ref).
Additional info:
NodeJS Version: v15.11.0
NPM Version: 7.6.3
PM2 Version: 4.5.6 (latest, by the time of writing this)
So, how do I get the Versioning field to display correctly?
Note: This isn't really an issue but rather a minor inconvenience. I just want to know what I'm doing wrong.

Azure Functions local HTTP trigger issue and solution

Just wanted to post the steps I took after running into the following error when trying to run an Azure Function HTTP Trigger locally in VS Code:
"[error] Incompatible Node.js version. The version you are using is v13.1.0,
but the runtime requires an LTS-covered major version. LTS-covered versions
have an even major version number (8.x, 10.x, etc.) as per
https://github.com/nodejs/Release#release-plan. For deployed code, change
WEBSITENODEDEFAULT_VERSION to '~10' in App Settings. Locally, install or
switch to a supported node version (make sure to quit and restart your code
editor to pick up the changes)."
(1.) install NVM. Instructions here: https://github.com/nvm-sh/nvm#installing-and-updating
(2.) install NVS. Instructions here: https://github.com/jasongin/nvs
(3.) in your VS code terminal, run:
nvs add 12.16.1
nvs use node/12.16.1/x64
(4.) edit your launch.json to the following:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node Functions",
"type": "node",
"request": "attach",
"port": 5555,
"preLaunchTask": "func: host start"
}
],
"node": {
"runtimeVersion": "12.16.1"
}
}
(5.) in your VS code terminal, run:
func start

node.js on google app engine: different version running vs specified in package.json

I have a node application on GAE (Google App Engine) flex environment. In the code, package.json specifies: "node": "8.11.4":
{
"name": "prismic-universal-app",
"version": "1.0.0",
"description": "",
"main": "public/js/compiled/server.js",
"engines": {
"node": "8.11.4"
},
"scripts": {
...
But when I open a Cloud Shell window from the google cloud console the project and run 'node --version', I get v8.9.4
Reading through google's documentation, I don't see anything yet about using a different version from what's in package.json. Does anyone know if google has another way to determine what version of node will ultimately be used? Or is there another spot where Node.js version can be set that may be conflicting with package.json?
The Cloud Shell is a GCP product separate from GAE (flexible). It does not execute on your GAE flexible app instance. From Virtual machine instance:
When you start Cloud Shell, it provisions a g1-small Google Compute
Engine virtual machine running a Debian-based Linux operating
system.
The info you obtained is from that VM.
To check the info on your GAE flexible app instance, you need to connect to it specifically, see Connecting to the instance.

Azure WebJobs Node.js version

For a Azure Web App, we have set environment WEBSITE_NODE_DEFAULT_VERSION to 6.3.0 and also specified the node engine in www-server/package.json:
"engines": {
"node": "6.x.x",
"npm": "3.x.x"
}
This seems fine - process.versions.node shows that our Web App is using node 6.3.0.
However WebJobs on the same Web App instance seems to use Node 5.9.1 instead of 6.3.0. (We are using Microsoft.Azure.WebJobs.Script.Host.exe Queue Trigger)
How do we set the node version for Azure WebJobs? We need at-least 6.1.0

Bluemix error: Module version mismatch

I am trying to run a node.js application that uses PouchDB (a local CouchDB implementation). I can run this successfully locally and even upload it and build it on my Bluemix instance. However, whenever I send a request to my app, I do not get a response and I see the following error in my Bluemix console:
[Error: Module version mismatch. Expected 46, got 14. This generally implies that leveldown was built with a different version of node than that which is running now. You may try fully removing and reinstalling PouchDB or leveldown to resolve.]
I have tried to add npm rebuild into my build pipeline above the npm install, which I can see does indeed do a rebuild. However, I still get the previous error.
A bit about my app: It is a bot for the Slack platform. A user sends a command and my Bluemix app then responds. My Bluemix app has multiple documents that PouchDB stores. As I say, all this runs and responds correctly on my development machine.
Here is my package.js for reference:
{
"name": "XXXXXXXXXXX",
"version": "0.x.0",
"description": "XXXXXXXXXXXX",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"repository": {
"type": "git",
"url": "XXXXXXXXXXX"
},
"keywords": [
"slack",
"bot",
"nodejs"
],
"author": "xxxxxxxxx",
"license": "MIT",
"dependencies": {
"bluebird": "^3.1.1",
"body-parser": "^1.14.2",
"cfenv": "^1.0.3",
"cheerio": "^0.19.0",
"express": "^4.13.3",
"pouchdb": "^5.1.0",
"request-promise": "^1.0.2"
},
"engines": {
"node": "^4.2.x",
"npm": "^2.14.x"
}
}
Also some additional history: I ran a prior version of my app on Bluemix when I was using MongoDB instead of PouchDB. My node version at the time was the default that Bluemix gave me when I started, which was version 0.12.x. However, this version didn't support arrow functions, which I make heavy use of now. Hence, the bump to node 4.2.x.
Thanks!
Edit: After some digging I found out that 'leveldown' (a dependency of PouchDB) makes use of npm prebuilds where available. What this means is that if a prebuild is available on their GitHub it will be downloaded instead of the source, as a convenience. Looking through the logs I notice that version 1.4.2 is being downloaded as the prebuild version through Bluemix. However, there is a version 1.4.3 available that looks like it solves my 'Expected 46, got 14` issue. So the new question is why is Bluemix doing this and how can I rectify it?
I tried to push on Bluemix the same version that you are using ("^5.1.0") in your package.json and it is working fine, even using node engine "4.0.x".
Moreover according to CF infrastructure, the runtime is build during application staging step, so the pouchdb module should be built with the right dependencies and references.
Have you tried to push your application again in order to force a full application restage?
If yes, the first step to understand what is going on is to get the application logs during the staging process and also as soon as this error message is returned.
So, on your terminal, run the following commands:
1 - cd into your source directory
2 - connect to Bluemix API
cf api https://api.[REGION].bluemix.net

where [REGION] is one of
eu-gb for United Kingdom
ng for US South
au-syd for Sydney
3 - Login to Bluemix and choose the right ORG and SPACE
cf login -u [BLUEMIX USERNAME]
cf target -o [BLUEMIX ORG] -s [BLUEMIX SPACE]
4 - push your application and, as soon as it has been staged, run
cf logs [app-name] --recent > staging_output.txt
5 - tail the application logs, running
cf logs [app-name]
and without closing it make the request that is generating the error message
6 - check the output generated at step #5 for details on where in the code your application is failing and on the failing module
After a lot of debugging the answer, as ever, was to delete my Bluemix application first and then push a new version via the build system. The leveldown prebuilt npm package that was causing the error was cached somewhere. I could only get rid of this by deleting my app. Nothing special there.

Resources