On Sep 18, 2014, at 10:39 AM, Aleksandra Czajka <[email protected]> wrote:

> you have client-side and server-side js files. how does node.js specify which 
> .js file runs on server and which runs on browser.

If you send HTML to the browser that references URLs to load JS from, they'll 
run in the browser; if those URLs map to a node app and it serves them (either 
as static assets, or with some kind of processing done to them, or generated 
live), then node is what "decides" to send them to the browser in response, but 
it's at the browser's request.

Node apps themselves are javascript, so starting from the main script, 
require() will load files and evaluate them within node.

You can mix the two, or keep them strictly separate -- if you're making an app 
that has different stuff in the browser than on the server (the norm) than 
maybe having them in separate folders is useful (often main code in the root, 
and browser stuff in public/ is what's done)

If you're writing isomorphic modules -- where they work the same in the browser 
and node, and especially if you do the work to make your app work that way, 
then mixing them might make more sense. This is a natural thing when you're 
using tools like browserify to make javascript bundles that run in the browser. 
Then which is browser and which is 'node' is more a matter of following a 
dependency chain -- what script starts, and what requires are called and what 
modules are loaded? 

It's okay for them to mix. It's up to you to keep yourself from going nuts when 
maintaining it though. There's no magic in any of this -- require is a pretty 
simple function; browserify is more complex but still based on some very simple 
principles. Browsers requesting javascript is the same as it has been since the 
<script> tag.

Aria

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/94672F0D-3A9A-4002-A552-50959C4902A8%40nbtsc.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to