DEV Community

boroskoyo
boroskoyo

Posted on • Updated on • Originally published at Medium

Collect Realtime Stack Traces from NodeJS Applications

Whether you are working on a dev branch or prod, you can now remotely debug your running Node.js applications using Sidekick’s web IDE.

In this post, I’ll show you how you can quickstart collecting stack traces from your Node.js applications using Sidekick. All without restarting & redeploying.

To keep everything nice and short I’ve started with the Hello World example from Express.js’ website. (http://expressjs.com/en/starter/hello-world.html)

Then I plugged in body-parser and added a new endpoint to demonstrate what you can achieve in a few seconds.

const express = require('express')  
const app = express()  
const port = 3000  
const bodyParser = require('body-parser')  

app.use(bodyParser.json())  

app.get('/', (req, res) => {  
  res.send('Hello World!')  
})  

app.post('/:id', (req, res) => {  
    let body = req.body  
    res.json(req.body.foo)  
  })  

app.listen(port, () => {  
  console.log(\`Example app listening on port ${port}\`)  
})

Enter fullscreen mode Exit fullscreen mode

So as you can see, my new endpoint is returning a part of the request body. Now we will use Sidekick to observe more and see what other information was included in the request body.

First, we will install our Sidekick Node.js agent.

npm install @runsidekick/sidekick-agent-nodejs

Then we will sign in to our Sidekick account and copy the API Key of our workspace.

Sidekick comes with a 7-day free trial so you can use this link to sign up and follow along with this article.

https://app.runsidekick.com/

Then we will add the Sidekick agent on top of our project. Final code will look like this.

const SidekickDebugger = require('@runsidekick/sidekick-agent-nodejs');  

SidekickDebugger.start({   
    apiKey: 'your-sidekick-api-key'  
});  

const express = require('express')  
…

Enter fullscreen mode Exit fullscreen mode

And we are good to go. Now we can run our application and start observing its state on the go.

To put your first tracepoint, head to app.runsidekick.com

Select your running application.

Add your tracepoint and call your endpoint to collect related data.

There you go, now that you have collected your data you can observe what is going on behind the curtains.


(checkout the initial image for the zoomed in version)

As you can see starting with Sidekick is a breeze.

If you liked this article and learn more about Sidekick you can check out our docs and start using it right away!

Top comments (0)