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'
- The docs of the project are here: https://github.com/allnulled/nodelive. You will find other utilities inside, like asking for strings or option selectors, things like that.
Top comments (0)