You can start a REPL at any time using the repl core module. With useGlobal you can make the global scope shared, and using context you can pass in whatever local context you need:
import repl from 'repl'
const r = repl.start({ useGlobal: true })
r.context.someStuff = 123 // will be accessible as someStuff in REPL
Then you get the usual prompt in your console and you can interact with it to run commands and view variables. It runs in the same process as your application, so you can import/require modules and access their exports, etc. and their data will be shared with the rest of your code.
If you want to insert this at some specific point in your code and get full access to local variables there, you can use a custom eval function that calls JavaScript's eval in the local scope:
repl.start({
eval: (cmd, context, filename, callback) => {
with (context) callback(null, eval(cmd))
}
})
(Note: With this, defining new variables with let will not work across commands.)
To also get history in the programmatic REPL, you can take a look at repl-story or similar packages.
If you want to access a similar console through a web browser remotely (careful - security risk - best to make available only via SSH port forwarding), take a look at node-browser-repl.
In case you are looking a full debugger experience though, check out T.J. Crowder's answer about how to attach DevTools to a node.js application.