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?
An Absolute Beginner's Guide to Node.js
41–50 of 71 posts
Re: An Absolute Beginner's Guide to Node.js
#42Earlier 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".
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
#43Earlier 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.
C# Async and Await - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp...
Re: An Absolute Beginner's Guide to Node.js
#44Not 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…
Re: An Absolute Beginner's Guide to Node.js
#45Earlier 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.
Re: An Absolute Beginner's Guide to Node.js
#46Great 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.
Re: An Absolute Beginner's Guide to Node.js
#47Earlier 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...
Re: An Absolute Beginner's Guide to Node.js
#48Thank 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).
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
#49Earlier 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.
Re: An Absolute Beginner's Guide to Node.js
#50Earlier 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...