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:
> require.cache = {}; > t = require("./test");Related blog post: