Tip: load source from a file in the Node.js shell
Join the DZone community and get the full member experience.
Join For FreeNode.js is really handy as an interactive shell for JavaScript. Alas, there is no simple command for loading source code from an external file. This post describes a work-around.
File test.js:
exports.foo = function() { console.log("Hello world!"); };Interaction:
> var t = require("./test"); > t.foo() Hello world!Node caches modules. Thus, if the source file changes, you need to clear the module cache and re-require the module:
> module.moduleCache = {}; > t = require("./test");
shell
Node.js
Opinions expressed by DZone contributors are their own.
Comments