Creating a minimal Node.js module

I strongly believe in the minimalistic approach when creating examples. Here is one minimal module: module.exports = function() { return “Hello World”; }; Here is the main.js: var hello = require(“./hello.js”); var moduleExportsFunction = hello(); console.log(moduleExportsFunction); If you call node main.js, the output will be: Hello World So what you get after the require is…

Tagged

Escape from the CommonJS

Node.js uses CommonJS module loading. CommonJS module loading doesn’t work with the browsers. The reason is simple. JavaScript cannot load another JavaScript module from the disk. Two workarounds: One to run a program like Browserify. Browserify will look for calls to require(), resolve all dependencies, and gather the needed code into a single big file….

Tagged , ,