DEV Community

allnulled
allnulled

Posted on

Node.js code injection with nodelive

This is a small tutorial on how to debug your any Node.js program from your preferred editor.

You will be able to open a Node.js 'shell' to stop your program at some point of the code.

First, install nodelive:

$ npm i -s nodelive

Second, import the package:

const nodelive = require("nodelive")

Finally, open the editor:

await nodelive.editor({
  custom: "vars"
})

And boom!!! You are inside.

To output things by console, you con log them or return them.

You can use await directly, no need to wrap the code in the editor, which is very handy.

To get out and continue your program, just save the file automatically opened, empty.

And three more notes.

  • The await keyword will make the debugging blockant.
  • It will try to open Sublime Text by default. To configure this, set the variable:
nodelive.PREFERRED_EDITOR = 'brackets'

Top comments (0)