2

I have been wandering around and looking for an answer or a discussion, I know Why was nodejs created.It was taking JS out of the browser and make it able to be mainstream language to interact with the system resources like Files, IO and Network operations. If we look into the JavaScript Web API arent they doing the same thing as Nodejs. Suppose we have fs module in Nodejs to interacting with files and We have a Web api interface for that. We have a lot of API interfaces like to read Bluetooth or System Battery etc. I dont know if we can do IO in Web API or make network requests. So where exactly does Nodejs Differs from these Web APIs.

JavaScript Complete APIS Page on MDN.

Thanks.

4
  • "It was taking JS out of the browser" - You're quite wrong on that. JavaScript on the server existed way before Node.js, and JavaScript was designed as a mainstream language from the very beginning. It's only that using V8 as an engine made it competitive, and node became quite popular. Commented Jul 14, 2016 at 6:49
  • Thanks for the comment. Would you please elaborate on JavaScript on server before Nodejs. Commented Jul 14, 2016 at 6:54
  • en.wikipedia.org/wiki/JavaScript#Server-side_JavaScript Commented Jul 14, 2016 at 6:55
  • Yeah , But No one even used it on server,like any implementations, Or Maybe I dont know that. When Nodejs came along, Everybody starts using JS on server?? All we could see JavaScript as a Browser Language, and the Window Object. Commented Jul 14, 2016 at 7:00

1 Answer 1

6

You mentioned:

We have a Web api interface for [reading files in the browser]

Careful with this statement. JavaScript in the browser can't access your file system directly at will (a user has to affirmatively allow the browser to use a specific file, for example, by selecting a file with an input element). With node.js, however, you can access the file system directly (with the fs module, for example).

If we look into the JavaScript Web API arent they doing the same thing as Nodejs

This is a classic "venn diagram" visualization. Of course, there are many areas where JavaScript in the browser and node.js intersect because they're the same language.

Here is a list of some differences (and it is not all-inclusive by any stretch of the imagination):

  1. You can run servers with node.js (good luck running a server in your browser)
  2. You can access the filesystem directly with node.js (can't do this in the browser)
  3. You can spawn multiple processes with node.js
  4. JavaScript in the browser has a feature called web workers, for example (which isn't used in node.js)

That's all I could think of off the top of my head, but to sort of sum it up, node.js allows you to run code on a machine very much like you would run, say, Python, Java, Ruby, etc.

Sign up to request clarification or add additional context in comments.

3 Comments

That was very helpful. Off course you would need to allow the browser to access the file. And yes these Web API are not supported in all browsers.
Thanks for the response. :) I just want to know people opinions about these two.
@CKKhan no problem! Glad you found it helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.