I would like to exclusively use RequireJS for node.
I cannot seem to get it all to run in the same file when i run "node r.js file.js":
define('a', function () {
console.log("loaded a");
return {};
});
require(['a'], function(a){
});
is there any way to override define and require strictly with requirejs' definitions.
Also is there a way to do this strictly with r.js and not installing requirejs npm.
The require.js documentation includes a section on installing require with node.js .
First, you go to the console (assuming you have npm which you should) and type:
npm install requirejs
After that, you're all set up. First you need to require require (no pun intended), so in the top of your main js file, you need something like:
var requirejs = require('requirejs');
Then, you can configure it:
requirejs.config({/*your config with shims,etc goes here*/});
That's it! You can now use it:
requirejs(["module1","module2"],function(mod1,mod2){
//whatever here
});
There are more detailed instructions on this page.
You can use browserify.
Browserify lets you share code between the client and the server using node.js style require() statements. It shims common things for your like process.nextTick. It even shims modules like path, events and even vm.
I have personally used it in several production projects and it works.