Home » Node js » View Node JS Log Messages in Azure

View Node JS Log Messages in Azure

By Emily

After recently deploying a Node JS API to Azure, I needed to view log messages from the deployed instance because part of it wasn’t working as expected. In a Node JS API in Azure, log messaging is not switched on by default. In this post, I’ll explain how to enable logging in Azure and view the log messages.

Enable log messages in Azure

To enable log messages in an Azure Linux app :

  1. Go to the Azure Portal and log in
  2. Navigate to your app from the App Services list
  3. Click on App Service Logs which is in the Monitoring section
  4. Select File System
  5. In Quote MB specify the quota. I left mine as the default value.
  6. In Retention Period set the number of days you want the logs to be kept for
  7. Click Save
View Node JS logs in Azure

Write log messages in Node JS code

To create a log message that you will be able to view in Azure simply use console.log, like this:

app.get("/product", (req, res) => {
  const name = req.query.name;

  // A basic log message
  console.log("This is a log message");

  // A log message wrapped in back ticks so that a
  // variable can be included
  console.log(`The query param name: ${name} `);

  res.send({
    name: name,
  });
});

View the Log messages in Azure

To view the log messages in Azure from the Node JS app follow these steps :

  1. Go to the Azure portal
  2. Navigate to your app
  3. Click on Log Stream in the Monitoring section

A window will open and you’ll see your log messages appear in this window as the application runs. When you’re running your API locally in VS Code you’d be seeing these messages in either your terminal window or the debug console.

I’ve also written a post about using Log messages in Azure from a .Net Core API.