Miguel Teixeira
Miguel Teixeira

Reputation: 3

Node.js - Disabling Browser's Javascript

For instance, if a browser has javascript disabled does node.js still work or does it need a fallback?

I know this might be a stupid question, but i'm trying to prove to a friend that node.js works on the server-side and doesn't rely on the client side.

Upvotes: 0

Views: 2396

Answers (3)

The Spooniest
The Spooniest

Reputation: 2873

Node.js, in and of itself, will continue to work even if the browser has JavaScript disabled (or has no support for it to begin with). It is a server-side environment, and therefore has nothing to do with the browser. It does its work before the client even sees the page (or AJAX response, if you're doing those).

Node.js cannot bypass the browser's JavaScript settings, but that's true for any server-side development environment. If you make something in Node.js that depends on the client to calculate something and send it back, then that won't work properly if the browser has JavaScript disabled. So you do have to be careful not to lose track of what code is client-side and what is server-side, which is slightly more difficult when both types of code use the same language, but is still not very hard. As long as you do that, you will be fine.

Personally, my favorite kind of demo for this sort of thing is to use telnet, as @FredericHamidi mentioned. It's difficult to get more bare-bones than telnet, since it does almost nothing for you: there is no JavaScript, no CSS, not even HTML. There isn't even HTTP, really; it can't construct the request by itself, so you have to type it in manually (which isn't so bad if you stick to HTTP/0.9 and GET requests for your demos, but I don't recommend getting any more complex than that). To an untrained eye, it looks like you're hacking into the machine. But Node.js will still run, even when you're running on essentially the most bare-bones client possible.

Upvotes: 1

a--m
a--m

Reputation: 4782

As pointed by @frédéric-hamidi run a node server and then curl it:

nodejs

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('I don\'t need js on the browser!');
}).listen(80);

shell

curl http://web-07081482-2b2c-4e1b-9b1c-9ab20dccb92c.runnable.com/

You can show him this demo:

http://runnable.com/VM9-XCkU5E06W8gl/nodejs-so-for-node-js-and-hello-world

Upvotes: 1

Donald Supertramp
Donald Supertramp

Reputation: 74

You've already said it. Node code is interpreted on the server hosting your application, not on the client.

You could proof that to your friend by receiving a response from a node powered server from a browser that has disabled JS.

Upvotes: 0

Related Questions