Live data from Hacker News

An Absolute Beginner's Guide to Node.js

blog.modulus.io

41–50 of 71 posts

Re: An Absolute Beginner's Guide to Node.js

#41
post #9

Earlier quoted context omitted.

The main application runs in a single thread and then I/O activities happen in an event loop running with a small thread pool. Once one of those activities completes the event loop will give a signal to the main thread of the Node app and the callback will be executed. Not sure if that helped or just confused everyone.

So basically if you have an infinite loop in your app's one and only thread, none of the callbacks will happen because they have to run on that one thread?

Yep. Similar to how an infinite loop in the browser will freeze up the page - the browser only gets to control to draw by putting a draw function in the event loop, so if you hog the thread, the page can't update.

Re: An Absolute Beginner's Guide to Node.js

#42
post #23

Earlier quoted context omitted.

For being such a flawed language, it does get one thing right. That one thing made Ryan Dahl pick javascript and it is the relative absence of blocking IO calls. Instead you use events and callbacks.

> "relative absence of blocking IO calls." Do not confuse "language" with "standard library".

The whole event loop idea, which is core to javascript, allows for the single-threaded non-blocking I/O in a way that no other popular language does. Because of this, javascript has features that make this type of programming easy - first-class functions, anonymous functions, etc.

So, yes. Non-blocking I/O is a standard library feature, but it works because of language features.

Re: An Absolute Beginner's Guide to Node.js

#43

Earlier quoted context omitted.

> "relative absence of blocking IO calls." Do not confuse "language" with "standard library".

The whole event loop idea, which is core to javascript, allows for the single-threaded non-blocking I/O in a way that no other popular language does. Because of this, javascript has features that make this type of programming easy - first-class functions, anonymous functions, etc. So, yes. Non-blocking I/O is a standard library feature, but it works because of language features.

> allows for the single-threaded non-blocking I/O in a way that no other popular language does.

C# Async and Await - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp...

Re: An Absolute Beginner's Guide to Node.js

#44
post #16

Not trying to be flamy, but, once again... why people insist on pushing on projects based on a... renownedly flawed programming language? ..Yea JS. Today it's clear that the "only" reason for it being used is its widespread availability in browser, but that started in a time when you needed a way to change the mouse pointer from default to a rainbow colored one. But still js it's the programming language we build fra…

Try Typekit, it makes JS much, much better and it more or less is what JS will become in the future (it follows latest ECMAScript proposals)

Re: An Absolute Beginner's Guide to Node.js

#45

Earlier quoted context omitted.

Technically speaking, HTML 5 introduced web-workers which allows javascript to have multiple threads (see 1). However, it's still useful to think about them as being single threaded since workers are sandboxed, meaning they don't have access to the global namespace. This avoids issues commonly found in concurrent programming. E.g., separate threads cannot read and write to the same variable since they don't have acce…

While that's true, I don't believe it's applicable to node.js, so it's a bit out of scope for this article.

People coming from multi-threaded server environments should be aware that multi-threading does in fact exist in Node (scope of parent comment), but it's rather different from other more common concurrent event handling schemes. I.e., you cannot have shared mutable variables across threads (scope of article and ongoing async discussion). For examples, see https://npmjs.org/package/webworker-threads and https://github.com/cramforce/node-worker.

Re: An Absolute Beginner's Guide to Node.js

#46
post #8

Great post. Looks like you guys have a cool platform too. Any specifics about how it's better than what's out there?

I'd love to chat about the platform. I'm not sure if this is the correct forum for pimping it. I just don's to turn this comment area into a discussion of the platform. Hit us up on twitter @OnModulus or send an email to feedback@modulus.io.

Clicking on the modulus logo takes me to your blog site instead of your main site

Re: An Absolute Beginner's Guide to Node.js

#47
post #43

Earlier quoted context omitted.

The whole event loop idea, which is core to javascript, allows for the single-threaded non-blocking I/O in a way that no other popular language does. Because of this, javascript has features that make this type of programming easy - first-class functions, anonymous functions, etc. So, yes. Non-blocking I/O is a standard library feature, but it works because of language features.

> allows for the single-threaded non-blocking I/O in a way that no other popular language does. C# Async and Await - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp...

Twisted (Python) and EventMachine (Ruby) don't all of these do the same thing?

Re: An Absolute Beginner's Guide to Node.js

#48

Thank you for writing this. Keeping the target audience in mind, one thing you may want to consider is telling people how to stop the node server once its started (CTRL-C).

After teaching university, and now having spent the past few years teaching teens it's best not to take for granted what a student might know. Though I discovered that on all levels (not just by teaching the teenagers). When you say "absolute beginner", you've got to be careful not to make too many leaps.

The advice above regarding CTRL-C is good. An absolute beginner might not know this.

Also I noticed a leap in the "static file server" lesson. A beginner may not realize they have to create a public directory and will just get a very unfriendly "Cannot GET" error. This might be especially true as following the `npm install express` command, directories were generated automatically. This sets up an expectation that isn't fulfilled.

A little more handholding might keep you from answering as many questions and allow the beginner a really smooth entry.

Re: An Absolute Beginner's Guide to Node.js

#49
post #38

Earlier quoted context omitted.

Node was created to make scripting fast servers easy. Nothing more, nothing less. Because JS (as implemented in the browser and known by many programmers) didn't carry the baggage of blocking IO calls, Ryan thought it would be a good language for an event-loop based server. History of Node.js: http://www.youtube.com/watch?v=SAc0vQCC6UQ

Fast Web servers. There is absolutely nothing there that I could use to make, say, a fast database server.

[deleted]

Re: An Absolute Beginner's Guide to Node.js

#50
post #43

Earlier quoted context omitted.

The whole event loop idea, which is core to javascript, allows for the single-threaded non-blocking I/O in a way that no other popular language does. Because of this, javascript has features that make this type of programming easy - first-class functions, anonymous functions, etc. So, yes. Non-blocking I/O is a standard library feature, but it works because of language features.

> allows for the single-threaded non-blocking I/O in a way that no other popular language does. C# Async and Await - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp...

were those in the language before or after node came out?
Post reply on HN