Use LogDNA to monitor your Node.js application logs

Getting started with LogDNA

Log management is an essential part of software development process as it serves us a secondary data source that is readily available. The logs gives us a comprehensive record of our application’s behind the scenes activities to provide the evidence needed to ascertain the depth of any problem when you decide to investigate the system’s issue or security threat.

In this post we’ll demonstrate how to integrate LogDNA to track events from a basic Node.js application. We will log each sign in attempt for our basic app.

Getting started

Manifold makes it easy for developers working remotely to manage projects and services by providing a single source of truth to unify all external project services under one account. In this post, we’ll use Manifold to set up our project and generate single all-in-one project credentials.


First you’ll need to create an account on Manifold and Authenticate your account to get started.

Install Manifold

Next, you need to install the Manifold CLI tool, simply open a terminal window and run the following command:


brew install manifoldco/brew/manifold-cli


Create a new project

Now that you have installed Manifold locally, let’s go ahead and create a new Manifold project. Login to your Manifold dashboard and create a new project:

s 448926BC66B35F5D244CB30C6883AB3F269E9EE4B8EE385D9408478FDD763352 1548868274332 Screen+Shot+2019-01-30+at+5.43.37+PM

Give the project a name that suits your needs and click the Create project button. This will launch a new screen like this:

s 448926BC66B35F5D244CB30C6883AB3F269E9EE4B8EE385D9408478FDD763352 1548868369170 Screen+Shot+2019-01-30+at+5.54.56+PM

Having created the project, let’s add the LogDNA resource to it. Click the Add a new resource button and select LogDNA from the list of available services. Give the resource a preferred name. In my case, I’ll call it `logdna-resource` and click the Create resource button to create my new LogDNA account.

s 448926BC66B35F5D244CB30C6883AB3F269E9EE4B8EE385D9408478FDD763352 1548868190913 Screen+Shot+2019-01-30+at+6.07.25+PM

We have successfully added the LogDNA resource to our project. You can scroll down the page to view the project credentials and copy them for later use (however, I'll demonstrate using the Manifold CLI to access these securely).

The LogDNA dashboard will contain all our log data and equally allow us to perform operations on them. We’ll open it later to view our logs but next, let’s create our Node project.

Set up Node project

Haven completed the project set up on Manifold, it’s time to build our Node project to communicate with Manifold and send our logs across. By design, we intend to build a form to collect user details and register them to a database, however, in our case, we will be logging the users to our LogDNA management system where we can visualize the logged data.

Create project
To make this process smooth, i have created a repository with starter files for this project, clone it and we’ll update the project files gradually. Open a terminal and run:


$ git clone


Next, change directory to the project folder and install the server dependencies like so:


$ cd node-logdna
$ npm install


Since we’ll be building a user registration form for our app, open the index.html file in the views folder and update it with the code below:


<!-- views/index.html -->
<!DOCTYPE html>
    <title>Manifold Node.js Logging Demo</title>
    <meta name="description" content="A cool thing using Manifold">
    <link id="favicon" rel="icon" href="" type="image/x-icon">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link rel="stylesheet" href="/style.css">
    <header class="text-center">
       User registration
      <div class="container center_div">
        <form action="/api/log" method="POST" name="userdata" class="text-center">
          <div class="form-group row">
            <label for="name" class="col-sm-2 col-form-label">FullName</label>
            <div class="col-sm-10">
              <input id="name" name="name" type="text" class="form-control" placeholder="Full Name">
          <div class="form-group row">
            <label for="email" class="col-sm-2 col-form-label">Email</label>
            <div class="col-sm-10">
              <input id="email" name="email" type="email" class="form-control" placeholder="Email">
          <div class="form-group row">
            <label for="password" class="col-sm-2 col-form-label">Password</label>
            <div class="col-sm-10">
              <input id="password" name="password" type="password" class="form-control" placeholder="Password">

          <div class="form-group row">
            <div class="col-sm-10">
              <button type="submit" class="btn btn-primary ">Register</button>
  <script src=""
  <script src="/app.js"></script>


If you open the `index.html` file on the browser at the moment, you should have this output:

s 448926BC66B35F5D244CB30C6883AB3F269E9EE4B8EE385D9408478FDD763352 1548872703004 Screen+Shot+2019-01-30+at+7.23.06+PM

Next, let’s add the functionality that will get the user form details and post to our server. Open the `app.js` file in the public folder and update it with the code below:


$(function() {
 $("form").submit(function(event) {
   var user = {
     name: $('input#name').val(),
     email: $('input#email').val(),
     password: $('input#password').val()
   $.post("/loguser", { userData: user }, function() {


This will get the values of the form’s `<input>` elements, save them into the user  object and post it to our server. If you open the `server.js` file, you’ll see this exact code therein:



'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const Logger = require('logdna');

const log = Logger.setupDefaultLogger(process.env.KEY, {});
const app = express();
 app.use(bodyParser.urlencoded({ extended: true}));
 app.get("/", function (request, response) {
   response.sendFile(__dirname + '/views/index.html');
 });'/loguser', (req, res) => {
   res.json("User logged!");
 console.log('Serving on port 8000');


Notice: We installed logdna via npm and required it in our server file. When the user’s details arrives at the `/loguser` endpoint we defined on the client, we simply take the body of the request and log it using the LogDNA Logger.

Run app

Having completed the app, we’ll need its credentials on Manifold to run it. This is a good thing, with Manifold, we don’t have to copy the credentials, or create a separate `.env` file locally, Manifold handles all that for us. All we need to do is run this command:


$ manifold run --project node-logging-demo 'npm run start'


This command will require you to login by running *`manifold login`* or *`manifold oauth --github`* to login with Github.

The manifold run command will grab the latest application credentials for us from Manifold, then we pass the `--project` flag to identify which project we are referencing and finally pass the command that runs our server, `npm run server` in our case. We put the server command in quotes to help when your server command requires arguments to run. When you run the app, it’ll be live on `localhost:8000` on your browser. Open it up and log users like so:

s 448926BC66B35F5D244CB30C6883AB3F269E9EE4B8EE385D9408478FDD763352 1548930204319

To track login access logs for your application, open the LogDNA dashboard and navigate to the log views, and you will now now see a log for each login attempt:

s 448926BC66B35F5D244CB30C6883AB3F269E9EE4B8EE385D9408478FDD763352 1550684181399 Screen+Shot+2019-02-20+at+6.25.24+PM

There you have it

You've created a simple Node.js application which stores its application logs with LogDNA. You can now take advantage of all native LogDNA features with the centrally logged data such as search, analysis, indexing etc.

Now go try LogDNA out for your own application!

Recent posts

Related posts