You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node.js apps must be deployed with all the required NPM dependencies. The App Service deployment engine automatically runs `npm install --production` for you when you deploy a [Git repository](deploy-local-git.md), or a [Zip package](deploy-zip.md)[with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy). If you deploy your files using [FTP/S](deploy-ftp.md), however, you need to upload the required packages manually.
16
+
Node.js apps must be deployed with all the required npm dependencies. The App Service deployment engine automatically runs `npm install --production` for you when you deploy a [Git repository](deploy-local-git.md), or when you deploy a [Zip package](deploy-zip.md)[with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy). If you deploy your files using [FTP/S](deploy-ftp.md), however, you need to upload the required packages manually.
17
17
18
18
This guide provides key concepts and instructions for Node.js developers who deploy to App Service. If you've never used Azure App Service, follow the [Node.js quickstart](quickstart-nodejs.md) and [Node.js with MongoDB tutorial](tutorial-nodejs-mongodb-app.md) first.
19
19
@@ -64,7 +64,7 @@ az webapp config appsettings set --name <app-name> --resource-group <resource-gr
64
64
> [!NOTE]
65
65
> This example uses the recommended "tilde syntax" to target the latest available version of Node.js 16 runtime on App Service.
66
66
>
67
-
>Since the runtime is regularly patched and updated by the platform it's not recommended to target a specific minor version/patch as these are not guaranteed to be available due to potential security risks.
67
+
>Since the runtime is regularly patched and updated by the platform, we don't recommend that you target a specific minor version/patch as these are not guaranteed to be available due to potential security risks.
68
68
69
69
> [!NOTE]
70
70
> You should set the Node.js version in your project's `package.json`. The deployment engine runs in a separate process that contains all the supported Node.js versions.
@@ -92,13 +92,13 @@ Your Node.js app needs to listen to the right port to receive incoming requests.
92
92
93
93
::: zone pivot="platform-windows"
94
94
95
-
In App Service on Windows, Node.js apps are hosted with [IISNode](https://github.com/Azure/iisnode), and your Node.js app should listen to the port specified in the `process.env.PORT` variable. The following example shows how you do it in a simple Express app:
95
+
In App Service on Windows, Node.js apps are hosted with [IISNode](https://github.com/Azure/iisnode), and your Node.js app should listen to the port specified in the `process.env.PORT` variable. The following example shows how to do that in a simple Express app:
96
96
97
97
::: zone-end
98
98
99
99
::: zone pivot="platform-linux"
100
100
101
-
App Service sets the environment variable `PORT` in the Node.js container, and forwards the incoming requests to your container at that port number. To receive the requests, your app should listen to that port using `process.env.PORT`. The following example shows how you do it in a simple Express app:
101
+
App Service sets the environment variable `PORT` in the Node.js container, and forwards the incoming requests to your container at that port number. To receive the requests, your app should listen to that port using `process.env.PORT`. The following example shows how to do that in a simple Express app:
102
102
103
103
::: zone-end
104
104
@@ -120,39 +120,39 @@ app.listen(port, () => {
120
120
121
121
## Customize build automation
122
122
123
-
If you deploy your app using Git, or zip packages [with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy), the App Service build automation steps through the following sequence:
123
+
If you deploy your app by using Git, or by using zip packages [with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy), the App Service build automation steps through the following sequence:
124
124
125
-
1. Run custom script if specified by `PRE_BUILD_SCRIPT_PATH`.
125
+
1. Run custom script, if one is specified by `PRE_BUILD_SCRIPT_PATH`.
126
126
1. Run `npm install` without any flags, which includes npm `preinstall` and `postinstall` scripts and also installs `devDependencies`.
127
127
1. Run `npm run build` if a build script is specified in your *package.json*.
128
128
1. Run `npm run build:azure` if a build:azure script is specified in your *package.json*.
129
129
1. Run custom script if specified by `POST_BUILD_SCRIPT_PATH`.
130
130
131
131
> [!NOTE]
132
-
> As described in[npm docs](https://docs.npmjs.com/misc/scripts), scripts named `prebuild` and `postbuild` run before and after `build`, respectively, if specified. `preinstall` and `postinstall` run before and after `install`, respectively.
132
+
> As is noted in the[npm docs](https://docs.npmjs.com/misc/scripts), scripts named `prebuild` and `postbuild` run before and after `build`, respectively, if specified. `preinstall` and `postinstall` run before and after `install`, respectively.
133
133
134
134
`PRE_BUILD_COMMAND` and `POST_BUILD_COMMAND` are environment variables that are empty by default. To run pre-build commands, define `PRE_BUILD_COMMAND`. To run post-build commands, define `POST_BUILD_COMMAND`.
135
135
136
-
The following example specifies the two variables to a series of commands, separated by commas.
136
+
The following example uses the two variables to specify a series of commands, separated by commas.
137
137
138
138
```azurecli-interactive
139
139
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PRE_BUILD_COMMAND="echo foo, scripts/prebuild.sh"
140
140
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="echo foo, scripts/postbuild.sh"
141
141
```
142
142
143
-
For additional environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
143
+
For information about additional environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
144
144
145
145
For more information on how App Service runs and builds Node.js apps in Linux, see [Oryx documentation: How Node.js apps are detected and built](https://github.com/microsoft/Oryx/blob/master/doc/runtimes/nodejs.md).
146
146
147
147
## Configure Node.js server
148
148
149
-
The Node.js containers come with [PM2](https://pm2.keymetrics.io/), a production process manager. You can configure your app to start with PM2, or with NPM, or with a custom command.
149
+
The Node.js containers come with [PM2](https://pm2.keymetrics.io/), a production process manager. You can configure your app to start with PM2, with npm start, or with a custom command.
150
150
151
151
|Tool|Purpose|
152
152
|--|--|
153
153
|[Run with PM2](#run-with-pm2)|**Recommended** - Production or staging use. PM2 provides a full-service app management platform.|
154
-
|[Run npm start](#run-npm-start)|Development use only.|
155
-
|[Run custom command](#run-custom-command)|Either development or staging.|
154
+
|[Run with npm start](#run-with-npm-start)|Development use only.|
155
+
|[Run with a custom command](#run-with-a-custom-command)|Either development or staging.|
156
156
157
157
### Run with PM2
158
158
@@ -163,7 +163,7 @@ The container automatically starts your app with PM2 when one of the common Node
163
163
-*app.js*
164
164
-*index.js*
165
165
-*hostingstart.js*
166
-
- One of the following [PM2 files](https://pm2.keymetrics.io/docs/usage/application-declaration/#process-file): *process.json*and*ecosystem.config.js*
166
+
- One of the following [PM2 files](https://pm2.keymetrics.io/docs/usage/application-declaration/#process-file): *process.json*or*ecosystem.config.js*
167
167
168
168
You can also configure a custom start file with the following extensions:
169
169
@@ -179,15 +179,15 @@ To add a custom start file, run the following command in the [Cloud Shell](https
179
179
az webapp config set --resource-group <resource-group-name> --name <app-name> --startup-file "<filename-with-extension>"
180
180
```
181
181
182
-
### Run custom command
182
+
### Run with a custom command
183
183
184
184
App Service can start your app using a custom command, such as an executable like *run.sh*. For example, to run `npm run start:prod`, run the following command in the [Cloud Shell](https://shell.azure.com):
185
185
186
186
```azurecli-interactive
187
187
az webapp config set --resource-group <resource-group-name> --name <app-name> --startup-file "npm run start:prod"
188
188
```
189
189
190
-
### Run npm start
190
+
### Run with npm start
191
191
192
192
To start your app using `npm start`, just make sure a `start` script is in the *package.json* file. For example:
193
193
@@ -210,9 +210,6 @@ az webapp config set --resource-group <resource-group-name> --name <app-name> --
210
210
211
211
## Debug remotely
212
212
213
-
> [!NOTE]
214
-
> Remote debugging is currently in Preview.
215
-
216
213
You can debug your Node.js app remotely in [Visual Studio Code](https://code.visualstudio.com/) if you configure it to [run with PM2](#run-with-pm2), except when you run it using a *.config.js,*.yml, or *.yaml*.
217
214
218
215
In most cases, no extra configuration is required for your app. If your app is run with a *process.json* file (default or custom), it must have a `script` property in the JSON root. For example:
@@ -227,9 +224,9 @@ In most cases, no extra configuration is required for your app. If your app is r
227
224
228
225
To set up Visual Studio Code for remote debugging, install the [App Service extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureappservice). Follow the instructions on the extension page and sign in to Azure in Visual Studio Code.
229
226
230
-
In the Azure explorer, find the app you want to debug, right-click it and select **Start Remote Debugging**. Click**Yes** to enable it for your app. App Service starts a tunnel proxy for you and attaches the debugger. You can then make requests to the app and see the debugger pausing at break points.
227
+
In the Azure explorer, find the app you want to debug, right-click it and select **Start Remote Debugging**. Select**Yes** to enable remote debugging for your app. App Service starts a tunnel proxy for you and attaches the debugger. You can then make requests to the app and see the debugger pausing at break points.
231
228
232
-
Once finished with debugging, stop the debugger by selecting **Disconnect**. When prompted, you should click**Yes** to disable remote debugging. To disable it later, right-click your app again in the Azure explorer and select **Disable Remote Debugging**.
229
+
Once finished with debugging, stop the debugger by selecting **Disconnect**. When prompted, you should select**Yes** to disable remote debugging. To disable it later, right-click your app again in the Azure explorer and select **Disable Remote Debugging**.
233
230
234
231
::: zone-end
235
232
@@ -243,7 +240,7 @@ process.env.NODE_ENV
243
240
244
241
## Run Grunt/Bower/Gulp
245
242
246
-
By default, App Service build automation runs `npm install --production` when it recognizes a Node.js app is deployed through Git, or through Zip deployment [with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy). If your app requires any of the popular automation tools, such as Grunt, Bower, or Gulp, you need to supply a [custom deployment script](https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script) to run it.
243
+
By default, App Service build automation runs `npm install --production` when it recognizes that a Node.js app is deployed through Git, or through Zip deployment [with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy). If your app requires any of the popular automation tools, such as Grunt, Bower, or Gulp, you need to supply a [custom deployment script](https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script) to run it.
247
244
248
245
To enable your repository to run these tools, you need to add them to the dependencies in *package.json.* For example:
249
246
@@ -256,7 +253,7 @@ To enable your repository to run these tools, you need to add them to the depend
256
253
}
257
254
```
258
255
259
-
From a local terminal window, change directory to your repository root and run the following commands:
256
+
From a local terminal window, change the directory to your repository root and run the following commands:
260
257
261
258
```bash
262
259
npm install kuduscript -g
@@ -322,9 +319,9 @@ fi
322
319
323
320
## Detect HTTPS session
324
321
325
-
In App Service, [TLS/SSL termination](https://wikipedia.org/wiki/TLS_termination_proxy) happens at the network load balancers, so all HTTPS requests reach your app as unencrypted HTTP requests. If your app logic needs to check if the user requests are encrypted or not, inspect the `X-Forwarded-Proto` header.
322
+
In App Service, [TLS/SSL termination](https://wikipedia.org/wiki/TLS_termination_proxy) happens at the network load balancers, so all HTTPS requests reach your app as unencrypted HTTP requests. If your app logic needs to check if the user requests are encrypted, inspect the `X-Forwarded-Proto` header.
326
323
327
-
Popular web frameworks let you access the `X-Forwarded-*` information in your standard app pattern. In [Express](https://expressjs.com/), you can use [trust proxies](https://expressjs.com/guide/behind-proxies.html). For example:
324
+
Popular web frameworks let you access the `X-Forwarded-*` information in your standard app pattern. In [Express](https://expressjs.com/), you can use [trust proxies](https://expressjs.com/en/guide/behind-proxies.html). For example:
328
325
329
326
```javascript
330
327
app.set('trust proxy', 1)
@@ -352,12 +349,12 @@ if (req.secure) {
352
349
353
350
## URL rewrites
354
351
355
-
When deploying Node.js apps on Azure App Service for Linux, you may need to handle URL rewrites directly within your application. This is particularly useful for ensuring specific URL patterns are redirected to the correct endpoints without relying on web server configurations. There are several ways to accomplish URL rewrites in Node.js. One example is through the [express-urlrewrite](https://www.npmjs.com/package/express-urlrewrite) package.
352
+
When deploying Node.js apps on Azure App Service for Linux, you might need to handle URL rewrites directly within your application. This is particularly useful for ensuring specific URL patterns are redirected to the correct endpoints without relying on web server configurations. There are several ways to accomplish URL rewrites in Node.js. One example is through the [express-urlrewrite](https://www.npmjs.com/package/express-urlrewrite) package.
356
353
357
354
358
355
## Monitor with Application Insights
359
356
360
-
Application Insights allows you to monitor your application's performance, exceptions, and usage without making any code changes. To attach the App Insights agent, go to your web app in the Portal and select **Application Insights** under **Settings**, then select **Turn on Application Insights**. Next, select an existing App Insights resource or create a new one. Finally, select **Apply** at the bottom. To instrument your web app using PowerShell, please see [these instructions](/azure/azure-monitor/app/azure-web-apps-nodejs#enable-through-powershell)
357
+
Application Insights allows you to monitor your application's performance, exceptions, and usage without making any code changes. To attach the Application Insights agent, go to your web app in the portal, select **Application Insights** under **Settings**, and then select **Turn on Application Insights**. Next, select an existing Application Insights resource or create a new one. Finally, select **Apply** at the bottom. To instrument your web app using PowerShell, see [these instructions](/azure/azure-monitor/app/azure-web-apps-nodejs#enable-through-powershell)
361
358
362
359
This agent will monitor your server-side Node.js application. To monitor your client-side JavaScript, [add the JavaScript SDK to your project](/azure/azure-monitor/app/javascript).
363
360
@@ -371,16 +368,16 @@ When a working Node.js app behaves differently in App Service or has errors, try
371
368
372
369
-[Access the log stream](#access-diagnostic-logs).
373
370
- Test the app locally in production mode. App Service runs your Node.js apps in production mode, so you need to make sure that your project works as expected in production mode locally. For example:
374
-
- Depending on your *package.json*, different packages may be installed for production mode (`dependencies` vs. `devDependencies`).
375
-
- Certain web frameworks may deploy static files differently in production mode.
376
-
- Certain web frameworks may use custom startup scripts when running in production mode.
377
-
- Run your app in App Service in development mode. For example, in [MEAN.js](https://meanjs.org/), you can set your app to development mode in runtime by [setting the `NODE_ENV` app setting](configure-common.md).
371
+
- Depending on your *package.json*, different packages might be installed for production mode (`dependencies` vs. `devDependencies`).
372
+
- Certain web frameworks might deploy static files differently in production mode.
373
+
- Certain web frameworks might use custom startup scripts when running in production mode.
374
+
- Run your app in App Service in development mode. For example, in [MEAN.js](https://meanjs.org/), you can set your app to development mode at runtime by [setting the `NODE_ENV` app setting](configure-common.md).
378
375
379
376
::: zone pivot="platform-windows"
380
377
381
378
#### You do not have permission to view this directory or page
382
379
383
-
After deploying your Node.js code to a native Windows app in App Service, you may see the message `You do not have permission to view this directory or page.` in the browser when navigating to your app's URL. This is most likely because you don't have a *web.config* file (see the [template](https://github.com/projectkudu/kudu/blob/master/Kudu.Core/Scripts/iisnode.config.template) and an [example](https://github.com/Azure-Samples/nodejs-docs-hello-world/blob/master/web.config)).
380
+
After deploying your Node.js code to a native Windows app in App Service, you might see the message `You do not have permission to view this directory or page` in the browser when navigating to your app's URL. This is most likely because you don't have a *web.config* file. (See the [template](https://github.com/projectkudu/kudu/blob/master/Kudu.Core/Scripts/iisnode.config.template) and an [example](https://github.com/Azure-Samples/nodejs-docs-hello-world/blob/master/web.config).)
384
381
385
382
If you deploy your files by using Git, or by using ZIP deployment [with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy), the deployment engine generates a *web.config* in the web root of your app (`%HOME%\site\wwwroot`) automatically if one of the following conditions is true:
386
383
@@ -389,7 +386,7 @@ If you deploy your files by using Git, or by using ZIP deployment [with build au
389
386
390
387
The generated *web.config* is tailored to the detected start script. For other deployment methods, add this *web.config* manually. Make sure the file is formatted properly.
391
388
392
-
If you use [ZIP deployment](deploy-zip.md) (through Visual Studio Code, for example), be sure to [enable build automation](deploy-zip.md#enable-build-automation-for-zip-deploy) because it's not enabled by default. [`az webapp up`](/cli/azure/webapp#az-webapp-up) uses ZIP deployment with build automation enabled.
389
+
If you use [ZIP deployment](deploy-zip.md) (through Visual Studio Code, for example), be sure to [enable build automation](deploy-zip.md#enable-build-automation-for-zip-deploy). It's not enabled by default. [`az webapp up`](/cli/azure/webapp#az-webapp-up) uses ZIP deployment with build automation enabled.
393
390
394
391
::: zone-end
395
392
@@ -407,7 +404,7 @@ If you use [ZIP deployment](deploy-zip.md) (through Visual Studio Code, for exam
407
404
::: zone pivot="platform-linux"
408
405
409
406
> [!div class="nextstepaction"]
410
-
> [App Service Linux FAQ](faq-app-service-linux.yml)
407
+
> [Azure App Service on Linux FAQ](faq-app-service-linux.yml)
0 commit comments