Reputation: 493
I setup a website with regular client side RequireJS today. Than I did some research on node, got that installed and setup my first module in node. When I setup the first require, I loaded the Require.JS file and I get all that. The thing that is confusing me is, I created a file called test.js and within that I am including:
var require = require("requirejs");
which is actually including the node require, not the original require library I was using right?
So like are they completely different? Can they used together?
Upvotes: 2
Views: 3150
Reputation: 841
Doesn't Node already have a module loader?
Yes Node does.
That loader uses the CommonJS module format. The CommonJS module format is non-optimal for the browser, and I do not agree with some of the trade-offs made in the CommonJS module format. By using RequireJS on the server, you can use one format for all your modules, whether they are running server side or in the browser. That way you can preserve the speed benefits and easy debugging you get with RequireJS in the browser, and not have to worry about extra translation costs for moving between two formats. If you want to use define() for your modules but still run them in Node without needing to run RequireJS on the server, see the section below about using amdefine.
Source: http://requirejs.org/docs/node.html#1
Upvotes: 4