How to use require.js in node.js?
why the following code does not work?
var requirejs = require('requirejs');
requirejs.config({
nodeRequire: require
});
requirejs(['foo'],
function (foo) {
console.log(foo);
});
I have tried various things, including using requirejs(['./foo']. I'm unable to get anything to work.
I have a file foo.js in the same directory as the main file (the one with the above code). I run the main file with node and foo is undefined. From the examples given on requirejs.org it looks like I am doing it right, but I am certain I am misinterpreting something.