Where does node.js fit into the web development context?

I know that node.js is called the "event driven I / O" server-side javascript hosted on the Javascript V8 engine. I visited the node.js website and then read the Wikipedia entry, but could not fully understand where to use it and how it would be useful. "Event-IO"? "V8 Javascript engine"? In some context though, I see that using “server-side” javascript is a bit overkill. I take, for example, this piece of code in the wikipedia node.js entry:

var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n'); }).listen(8000); console.log('Server running at http://127.0.0.1:8000/'); 

I thought, is there really a significant goal for starting a server that especially supports javascript files that run in the application input?

I also searched the node.js repository on github to find out more about how it works, and it turns out that some of its modules are written in C ++. So this is not javascript at all?

Can someone give me a clear explanation about all this? Sorry if the question is not clear or something like that, I'm just a beginner. Understand any input / suggestion. thanks

+7
source share
3 answers

The node.js server is, more simply, a replacement for something like the Apache web server, but it is largely written in JavaScript, which runs on the server (executed by the V8 engine) and not on the client side. It can be expanded with "native code" modules (written, for example, C ++) wrapped in a JavaScript interface to add functionality, but most node.js AFAIK modules are pure JavaScript.

“Event driven I / O” is just a term that describes the usual asynchronous callback mechanisms that you are used to in JavaScript. In node.js, you are calling callbacks for all kinds of things, and your function is being called when the corresponding event occurs.

Depending on how many modules you add, the node.js server is relatively lightweight compared to something like Apache and in a way is much simpler.

Two main advantages for node.js, I see:

  • It allows you to write both server and client parts of a web application in one language. In some cases, you can use the same code on both sides.
  • It makes server-side coding available to all those web developers who know JavaScript without having to learn a more common server language such as PHP or Java.

Here is an article I just stumbled upon that might shed some light: What is node.js?

+9
source

Although I can't add much to what @sje said, I will repeat this blog link that he shared, as this is the best resource I have found to explain nodejs quickly:

http://radar.oreilly.com/2011/07/what-is-node.html

Also note that this is from OReilly, which most of us know as the publisher of the best links for programmers on the market in general;)

I thought, is there really a significant goal for starting a server that especially supports javascript files that run in the application input?

This is completely wrong. This is the most incorrect node assumption you could make. node runs javascript on the server in the same way that ruby ​​or php or asp.net code is executed. The fact that the browser can also run javascript is not related to node.

It is assumed that you can share modules between the server and the client (for example, procedures for checking form data), but in general, the code bases are different from each other, since they are designed for different things.

I also searched the node.js repository on github to find out more about how it works, and it turns out that some of its modules are written in C ++. So this is not javascript at all?

Yes, node is a server that interprets javascript using the V8 engine. It has to be written in something. I'll give you a comparison: Microsoft.NET code is mostly written in .NET on top of .NET, but the main code that actually does the job is the runtime (the CLR, as most people refer to it) that manages the managed-code, this The code is written in C. The same with node. Yes, most of them (as you saw) are written in javascript, but the main libraries that run everything else are written in C.

Can someone give me a clear explanation about all this? Sorry if the question is not clear or something like that, I'm just a beginner. Understand any input / suggestion. thanks

Hope this helps clarify this in part. There's a lot to cover, and without going into evented-io (which includes an understanding of processes and flows and access to io, and more), this is pretty much the main high-level answer to this question. I invite you to the nodejs room on the chat server here, if you like, for more casual discussions that are fluid. http://chat.stackoverflow.com/rooms/642/node-js

Regarding the first question you asked:

Where does he fit?

In the same place, ruby ​​and php, perl and python and asp.net are used. The server generates the code that the client receives.

+3
source

I have not seen anyone give a simple answer to this.

Node.js:

  • javascript engine v8
  • event loop
  • some C ++ bindings, among other things, provide v8 I / O capabilities (both network and IO files)

It is important to note that Node does not have to be used for web development. His goal is "evented IO."

+1
source

All Articles