1
votes

I am trying to deploy my node.js app on Azure webapp via bitbucket.

when I checked the the wwwroot folder on kudu console, I could not find any node_modules folder and hence the app failed to start

I have tried both npm install and npm install --production in kudu console (inside the wwwroot folder), and I could see the node_modules and files being install via filezilla.... however when I try to start the app again, the node_modules just disappears, can't see it neither in kudu console nor in filezilla.

the package.json file in the project folder:

{
  "name": "fo",
  "version": "1.0.0",
  "description": "xx xx xx",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "xx xx",
  "license": "MIT",
  "dependencies": {
    "angular-map-it": "0.0.20",
    "angular-maps": "^6.0.1",
    "angular-waypoints": "^2.0.0",
    "axios": "^0.19.0",
    "bcrypt": "^3.0.6",
    "bluebird": "^3.5.5",
    "body-parser": "^1.19.0",
    "connect-mongodb-session": "^2.2.0",
    "convert-json": "^0.5.0",
    "csvtojson": "^2.0.10",
    "dotenv": "^8.0.0",
    "express": "^4.17.1",
    "express-session": "^1.16.2",
    "fixed-width-string": "^1.0.0",
    "guid": "0.0.12",
    "json2csv": "^4.5.2",
    "jsontoxml": "^1.0.1",
    "moment": "^2.24.0",
    "moment-business-days": "^1.1.3",
    "money": "^0.2.0",
    "mongoose": "^5.6.4",
    "multer": "^1.4.1",
    "ng-storage": "^0.3.2",
    "node-crisp-api": "^1.8.3",
    "nodemailer": "^6.3.0",
    "objects-to-csv": "^1.0.1",
    "open-exchange-rates": "^0.3.0",
    "sanitize": "^2.1.0",
    "svg-assets-cache": "^1.1.3"
  }
}

I don't understand, how people make node.js app work on azure? why node_modules is disappearing? and why azure is not automatically installing them based on my package.json??

1

1 Answers

0
votes

Azure App Service understands package.json and npm-shrinkwrap.json files and can install modules based on entries in these files.

Azure App Service does not support all native modules and might fail when compiling modules with specific prerequisites. While some popular modules like MongoDB have optional native dependencies and work fine without them, the following workarounds proved successful with almost all native modules available today:

Navigate to Kudu - https://yoursite.scm.azurewebsites.net/

Locate the wwwroot folder and run the install command command.

cd site

cd wwwroot

npm install

Run npm install on a Windows machine that has all the native module's prerequisites installed. Then, deploy the created node_modules folder as part of the application to Azure App Service. Before compiling, check that your local Node.js installation has matching architecture and the version is as close as possible to the one used in Azure (the current values can be checked on runtime from properties process.arch and process.version). So, ensure that

Azure App Service can be configured to execute custom bash or shell scripts during deployment, giving you the opportunity to execute custom commands and precisely configure the way npm install is being run. For a video showing how to configure that environment, see Custom Website Deployment Scripts with Kudu. Kindly ensure that all the configuration is appropriate. If the issue still persist, kindly let us know what specific error message you receive ( app failed to start) for further investigation and also take a look at this ‘Best practices and troubleshooting guide for node applications on Azure App Service Windows’ for more details on the topic.