Cannot upgrade Node.js version in Azure App Service - node.js

My Azure app service is running Node.js version 0.10:
> node -v
D:\home\site\wwwroot
v0.10.28
I am trying to upgrade it to version 8.
There's an article here describing how to do that: https://learn.microsoft.com/en-us/azure/nodejs-specify-node-version-azure-apps
First, I added the key in the Application Settings in Azure Portal:
It didn't work, so I also changed packages.json:
{
"name": "azure_cosmos_db_webservice",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node --inspect server.js"
},
"engines":{"node": "8.x"}, <-- This line added by me
"dependencies": {
"async": "^2.1.2",
"body-parser": "~1.15.2",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"documentdb": "^1.10.0",
"dotenv": "^4.0.0",
"express": "~4.14.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
}
}
I've restarted the app service several times by stopping and starting it again.
However, node -v in the console in Azure Portal is still showing the version as 0.10.28.
What did I miss?

Turns out that 8.x was not a correct syntax.
I've changed it to 8.1.4 both in packages.json and in the Application Settings, and it worked.
I found the list of supported versions here:
https://MYSITE.scm.azurewebsites.net/api/diagnostics/runtime

Related

Error: Cannot find module '#heroku/buildpack-registry'

I am trying to deploy a web app on Heroku. I am getting the following error
Error: Cannot find module '#heroku/buildpack-registry'
I tried adding the version of node I am using but still didn't help.
I also upgraded Heroku using npm i heroku#7.59.0 this too didn't help.
Any thoughts on this?
This is my package.json
{"name":"gssrDB",
"engines": {
"node": "14.18.0"
}
,
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js"
},
"dependencies": {
"#heroku-cli/plugin-buildpacks": "^7.54.0",
"#heroku/buildpack-registry": "^1.0.1",
"async-file": "^2.0.2",
"cli-ux": "^4.9.3",
"dotenv": "^9.0.2",
"ejs": "^3.1.6",
"ejs-mate": "^3.0.0",
"express": "^4.17.1",
"got": "^8.3.2",
"heroku": "^7.59.0",
"mongodb": "^3.6.6",
"mongoose": "^5.12.9",
"nodemon": "^2.0.13",
"phoenix": "^1.6.0"
}
}
I solved it like this in terminal
$ heroku plugins:install buildpack-registry
$ heroku plugins:install buildpacks
may be it works
I faced a similar problem, and I solved it by using proper node version.
For the current heroku version, node16 works, otherwise it cause error in buildpack
Two things helped in fixing this:
update the heroku CLI
npm install -g heroku
Adding the engines in the package.json with the currently installed node and npm versions
"node": "14.18.0",
"npm": "7.6.3"
}

NodeJS API deployement on AWS with Elastic Beanstalk

I'm looking for deploying my NodeJS API with AWS.
I tried to use Elastic Beanstalk but I always get this issue:
Image of the error I get
There is my package.json
{
"name": "",
"scripts": {
"start": "node server.js"
},
"version": "0.0.0",
"private": true,
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"express": "^4.16.4",
"hammerjs": "^2.0.8",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.4.20",
"mongoose-unique-validator": "^2.0.2",
"multer": "^1.4.1",
"tslib": "^1.9.0"
}
}
And I also have a nodecommand.config into a folder named ".ebextensions"
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
Also, is Elastic Beanstalk the best way to deploy my API ?
Thx for the answers !
Based on the comments.
The primary issue was using rar for deployment packaged instead of zip. After fixing that, config files had to be adjusted to work with Amazon Liunx 2.

How can I install a custom node version on Azure App Service for Windows

I'm trying to upgrade my Meteor app. Meteor recommends a specific version of Node to be used when deploying an app. For the latest version of Meteor this is Node 8.15.1.
Now I checked the Kudu management app for App Service which shows all installed (Node) runtimes (https://x.scm.azurewebsites.net/api/diagnostics/runtime) and I'm surprised to learn that the latest installed Node 8 version is 8.11.1, which is more then a year old (!).
How can I use the recommended version of Node (8.15.1) on my App Service for Windows?
I'm unable to switch to a Linux-based App Service Plan atm. If I was able to, I could use a different Docker base image.
Edit: I’ve tried setting the ‘WEBSITE_NODE_DEFAULT_VERSION’ setting, but that only works for Node versions available on App Service
You have to do the following to upgrade to latest version of Node.JS
1) package.json
put the following in your package.json
{
"name": "azure_cosmos_db_webservice",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node --inspect server.js"
},
"engines":{"node": "8.x"},
"dependencies": {
"async": "^2.1.2",
"body-parser": "~1.15.2",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"documentdb": "^1.10.0",
"dotenv": "^4.0.0",
"express": "~4.14.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
}
}
2) Application Setting of node js App in portal
Go to Application Settings, and update the value for WEBSITE_NODE_DEFAULT_VERSION to 8.15.1
It should work then. Hope it helps.

MarkLogic npm issues

I'm having issue while I'm installing MarkLogic. When I execute the command
npm install marklogic --save
I'm getting an error. It says
Refusing to install marklogic as a dependency of itself
package.json:
{
"name": "marklogic",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"jade": "~1.11.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
}
}
Checking -- if you cloned the MarkLogic Node.js API project, then ran the npm install command that you show above, I'd expect to see this error. Is that what's happening?
Edit: elevating #grtjn's point from the comment: When selecting a name for your package, it has to be unique. "marklogic" is the name of an existing package, and therefore conflicted with the same name used for the package you were building.

Heroku: Cannot find module 'mongodb'

OK, I have an express app which is throwing this error at launch when deployed to Heroku. The app compiles and runs fine locally:
Cannot find module 'mongodb'
This app was running until I redeployed it yesterday ... here is my package.json which was unchanged
{
"name": "fitness-tracker",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.9.0",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"promise": "~6.0.1",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3",
"debug": "~2.0.0",
"mongodb-core": "*",
"mongoskin": "~2.0.0",
"express-handlebars": "~1.1.0",
"moment": "~2.0.0",
"moment-timezone": "^0.3.1",
"q": "~1.0.1",
"compass": "~0.1.0",
"apm": "*"
},
"devDependencies": {
"moment-timezone": "^0.3.1"
}
Ideas?
So the issue was package's resolution based on node version. Since NodeJS is rapidly evolving, it's a good practice to include engines specification in your package.json.
When doing automatic deployments on various cloud providers, this helps them to use only specified node & npm version. This was all the packages that get fetches are built for that node version hence less chances of app to misbehave.
Read more: https://docs.npmjs.com/files/package.json#engines
Also always worth a try: disable the Heroku build cache to recreate the node_modules directory.
In the Heroku CLI write:
$ heroku config:set NODE_MODULES_CACHE=false
$ git commit -am 'disable node_modules cache' --allow-empty
$ git push heroku master
As described here.

Resources