Want a NodeBB REPL (command line interface)?

NodeBB Plugins
  • I wanted to debug some code I had written in my plugin and did a quick search to see if I could create a Node.js REPL that would function in the context of my plugin. It turned out to be quite simple to do.

    Just add this to your plugin's static:app.load method:

          setTimeout(function() {
            console.log("About to start REPL");
            var repl = require("repl");
            var util = require('util');
            var replServer = repl.start({
              prompt: "swf-cms> ",
              breakEvalOnSigint: true,
              ignoreUndefined: true,
              useGlobal: true,
              useColors: true
            var context = replServer.context;
            context.require = require;
            context.module = module;
            context.context = util.inspect(replServer.context, {depth: 0});
          }, 3000);

    You'll want to wrap this in something to prevent it from running outside of dev mode. Also, load up the context object with anything that you want to be conveniently available in the REPL. FYI, I used the setTimeout to give Nodebb a chance to finish loading before it gives you the prompt.

    Have fun.

Suggested Topics

| | | |