I am a PHP developer and have recently made some use of node JS with express.
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.
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#
consider this sample code
var express = require('express'); var app = express();
app.get('/some_page', function(req, res) { res.send('hello world'); });
app.listen(3000);
There is no JS involved so 'hello world' is sent to the browser and is rendered by the browser.
But what if the code was
var express = require('express'); var app = express();
app.get('/', function(req, res){ res.send('console.log('hello world')'); });
app.listen(3000);
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.