• Uncategorized

About node.js : Unable-to-deploy-NodeJS-Fastify-app-in-Azure-App-Service-Linux

Question Detail

I’m stuck in deploying my fastify app on Azure app service linux. I’m using azure devops for pushing my code to app service. I’m using 8080 port for running my application and its works fine on my local.
localhost screenshot

But the same code is not working on my Azure app service linux. Below are my Azure application setting variables.

    "value": "14.15.1",
    "value": "400"
    "name": "WEBSITES_PORT",
    "value": "8080"

My Fastify start code

const start_server = async() => {
    try {
        const PORT = process.env.port || 8080;
        await fastify.listen(PORT, () => console.log('SERVER LISTENING AT PORT : '+ PORT));
    } catch (error) {

Azure log stream message

2021-12-25T07:36:19.072325334Z > [email protected] start /home/site/wwwroot
2021-12-25T07:36:19.072333734Z > node index
2021-12-25T07:36:21.501580169Z └── / (GET)
2021-12-25T07:36:21.501681270Z     └── health (GET)
2021-12-25T07:36:21.510859135Z {"level":30,"time":1640417781510,"pid":48,"hostname":"70cc318278d7","msg":"Server listening at"}
2021-12-25T07:36:21.511455845Z SERVER LISTENING AT PORT : 8080

2021-12-25T07:42:53.185Z ERROR - Container appservice-fastify_0_1efa2fe9 for site appservice-fastify did not start within expected time limit. Elapsed time = 400.3492937 sec
2021-12-25T07:42:53.188Z ERROR - Container appservice-fastify_0_1efa2fe9 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2021-12-25T07:42:53.213Z INFO  - Stopping site appservice-fastify because it failed during startup.
2021-12-25T07:44:08  No new trace in the past 1 min(s).
2021-12-25T07:45:08  No new trace in the past 2 min(s).
2021-12-25T07:46:08  No new trace in the past 3 min(s).
2021-12-25T07:47:08  No new trace in the past 4 min(s).
2021-12-25T07:48:08  No new trace in the past 5 min(s).
2021-12-25T07:49:08  No new trace in the past 6 min(s).
2021-12-25T07:50:08  No new trace in the past 7 min(s).
2021-12-25T07:51:08  No new trace in the past 8 min(s).
2021-12-25T07:52:08  No new trace in the past 9 min(s).
2021-12-25T07:53:08  No new trace in the past 10 min(s).

2021-12-25T07:53:35.981Z INFO  - 14-lts_20210810.1 Pulling from appsvc/node
2021-12-25T07:53:35.984Z INFO  -  Digest: sha256:235466ae6c6309188679f757798c5e15063c8206d4dec2fd919a5c279140def1
2021-12-25T07:53:35.986Z INFO  -  Status: Image is up to date for mcr.microsoft.com/appsvc/node:14-lts_20210810.1
2021-12-25T07:53:35.993Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2021-12-25T07:53:36.052Z INFO  - Starting container for site
2021-12-25T07:53:36.053Z INFO  - docker run -d -p 8080:8080 --name appservice-fastify_0_f44cb2fd -e WEBSITES_PORT=8080 -e WEBSITE_SITE_NAME=appservice-fastify -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=appservice-fastify.azurewebsites.net -e WEBSITE_INSTANCE_ID=42864bd09e137c4d59228551c4bd55a9336afeee4f2ed34ea118913c305a339c appsvc/node:14-lts_20210810.1

When I navigate to /health route on my azure deployed site, I get below message
azure site image

I googled a lot on this issue but no luck. And there is no straight forward docs on this issue.
Can you guys guide me to resolve this issue.


Question Answer

Inside Docker, you should mention explicitly ''. By default fastify is listening only the localhost interface. To listen on all available IPv4 interfaces you should be modified to listen on like so I change it to the following

const start = async () => {
    try {
        const PORT = process.env.port || 8080;
        await fastify.listen(PORT,'', () => console.log('SERVER LISTENING AT PORT : '+ PORT))
    } catch (err) {



.listen binds to the local host, localhost, interface by default
( or ::1, depending on the operating system configuration). If you are running Fastify in a container (Docker, GCP, etc.), you may need to bind to Be careful when deciding to listen on all interfaces; it comes with inherent security risks. See the documentation for more information.

And make sure you have to use the recent fastify package version. Check the version in package.json file. Which follows

    "name": "fastify",
    "version": "3.0.0",
    "main": "server.js",

After changed in to recent version, the issue has fixed.

Use the Kudu log stream to see the detailed log information https://<your_app_name>.scm.azurewebsites.net/api/LogStream

Refer here

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.