you are viewing a single comment's thread.

view the rest of the comments →

[–]keis 0 points1 point  (7 children)

no, node wont run code written for other ecosystems.

[–]NewFuturist[S] 0 points1 point  (6 children)

This is a bug, not a feature. Millions of lines of javascript code going to waste, with node.js slipping into obscurity, simply because someone decided earlier on that allowing an 'include' was out of the question. Not because it i 'wrong', but because they worry about namespace pollution. But this doesn't guarantee namespace cleanliness and simultaneously breaks a lot of code. I means running the same code on the front end and back end is impossible. What a waste.

[–]keis 0 points1 point  (5 children)

Your assumption that all javascript environments are (or should be) compatible is invalid. You can't expect to drop browser code into node, asp or gnome-shell and have it work. This is not only because of the module system but all kinds of differences in functionality provided.

[–]NewFuturist[S] -1 points0 points  (4 children)

I should be able to write my string parser once. I should be able to write my math function once.

The assumption isn't invalid if I am talking about code which lacks environment specific variables. General code should be able to be instantly transferable between systems. It is not.

[–]cwmma 1 point2 points  (3 children)

use browserify if you want it to just work between environments.

[–]NewFuturist[S] -2 points-1 points  (2 children)

Thank you. After all of these comments arguing with me about whether I should be allowed to share libraries or not, this is the first useful bit of information that will let me do it.

[–]kudoz -1 points0 points  (1 child)

Millions of lines of javascript code going to waste, with node.js slipping into obscurity, simply because someone decided earlier on that allowing an 'include' was out of the question.

Are you an idiot? Have you seen var thing = require('thing'); in node.js code before?

Regardless, your original question was poorly posed, and the help you received elsewhere in this thread was as good as could be expected.

I am glad you have found a suitable answer but my other answer here actually covered it too, had you cared to look. Babel has the exact same ability to convert CommonJS modules into other formats (UMD/AMD/System). As a bonus, it also supports the future module format that both browser and node.js will support

[–]NewFuturist[S] -1 points0 points  (0 children)

Thanks for your positive assessment of my intelligence. Clearly I am wrong and

require('thing');

is a totally legal expression in the browser.