user4368224
user4368224

Reputation:

Heroku - Debugging a NodeJS Application Locally

I'm developing a NodeJS application and want to deploy it to Heroku. But the issue I'm having is that I want to debug it locally using the debugger in the IntelliJ IDE. But the only way to run it locally and populate the heroku environment variables is to run it with 'heroku local' but that avoids the IDE.

Is there anyway to link 'heroku local' with the IntelliJ IDE debugger?

Upvotes: 0

Views: 629

Answers (1)

Russell Santos
Russell Santos

Reputation: 411

Adding '--debug' or '--inspect' to your Procfile (depending on your node version) and using IntelliJ's Node.js Remote debugging should work(as long as you pass the correct debug port).

Your Procfile should look something like this:

web: node --debug index.js

Note: Use --inspect for Node versions >=8. And --debug for Node versions <8.

When you run heroku local it should look like this:

russ@lamia node-js-getting-started (master)*$ heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
1:03:20 PM web.1 |  Debugger listening on [::]:5858
1:03:20 PM web.1 |  Listening on 5000

You can then create a Node.js Remote Debug Configuration in IntelliJ by following these instructions: https://www.jetbrains.com/help/idea/run-debug-configuration-attach-to-node-js-chrome.html.

Make sure to use the correct port number(printed by heroku local), and to use the correct debugging protocol. You should select 'Chrome or Node.js > 6.3 started with --inspect' if you used --inspect, and 'Node.js < 8 started with --debug' if you used --debug.

Upvotes: 3

Related Questions