title: node JS client vs server
body: <p>I am a PHP developer and have recently made some use of node JS with express.</p>
  
  <p>One thing i am confused about is how you tell your express server if a javascript file should be executed on the server or sent to the browser to be executed on the client side.</p>
  
  <p>In PHP this is not a problem because each filetype (php, pearl, jpg, js) has a dedicated location (server or client) where it runs. The same is true of HTTP apps programmed other languages such as Java and C#</p>
  
  <p>consider this sample code</p>
  
  <blockquote>
    <p>var express = require('express'); var app = express();</p>
    
    <p>app.get('/some_page', function(req, res)
    {    res.send('hello world');  });</p>
    
    <p>app.listen(3000);</p>
  </blockquote>
  
  <p>There is no JS involved so 'hello world' is sent to the browser and is rendered by the browser.</p>
  
  <p>But what if the code was </p>
  
  <blockquote>
    <p>var express = require('express'); var app = express();</p>
    
    <p>app.get('/', function(req, res){   res.send('console.log('hello
    world')'); });</p>
    
    <p>app.listen(3000);</p>
  </blockquote>
  
  <p>This time we have the JS function console.log()
  So how does node.js know if if should run this code or send it to the browser.</p>