Who is this FAQ for?
This is for Java and .NET developers wondering whether learning JavaScript on the back-end (i.e. Node.js) is worthwhile for their career.
Why should I trust this FAQ?
The author is someone who spent the first ten years of his career programming in C++, and the second ten years programming in JavaScript. He considers it the best career bet he made. Others have made the same switch.
How do I get started?
First, download and install Node: https://nodejs.org/en/download/.
Node is very simply a back-end runtime environment for JavaScript. It was created by Ryan Dahl in 2009. Under the hood, Node.js executes JavaScript using the V8 JavaScript engine, the same engine that powers the Google Chrome browser. Before Node.js, JavaScript primarily ran in browsers.
Then try this super simple getting started exercise. That’s a rudimentary, self-contained web server in just 8 lines of code.
What’s the best way to learn JavaScript syntax?
Any way you like. The syntax is relatively easy to pick up for anyone coming from a C++, Java or .NET background. The Mozilla Developer Network (MDN) documentation on JavaScript and other web technologies is considered almost canon by most developers. It includes tutorials, developer guides and a language reference.
What’s a good tutorial to get some hands on Node.js experience?
There are many. I personally like NodeSchool, which has an entire course titled LearnYouNode, which you can download and run on the command line, step-by-step.
If you’re more of a read-and-try-out kind of programmer, try this instead: https://books.goalkicker.com/NodeJSBook/
Nodejs.dev has another good introductory tutorial.
Who uses Node.js?
A large number of companies, including Netflix, Microsoft, Amazon Web Services, Paypal, Uber, LinkedIn, Trello and eBay.
How is JavaScript compiled in Node.js?
The V8 engine (which is used by Node.js) compiles JavaScript at runtime. That is to say, it is JIT compiled, not interpreted. So when you’re deploying a Node.js application, you’re basically deploying the source code. But when you’re running, you’re actually running machine code.
Does Node.js have a standard library?
Yes. See the Node.js API Documentation. HTTP, File System (fs) and Events are some of the more commonly used modules. Note that these are part of Node.js, and not JavaScript. JavaScript has its own “standard library” in the form of a list of built in objects and functions. These too, are available in the Node environment. But the usual window and document objects are obviously not available in Node.
But JavaScript is not type safe is it?
JavaScript tries to balance safety with ease and speed of development. For people who are used to working with more dangerous languages (such as C/C++), writing safe code in JS without assistance is actually quite easy. But if you really want, you can use TypeScript, which is an extension to the JavaScript language that can be compiled to JavaScript.
What about global variables and private variables?
That was in the past. Modern JavaScript is written using modules. Write all your code inside modules. That way, a module can only access what it imports, and other modules can only access what that module exports.
What’s the Node.js library ecosystem like?
It’s huge. In fact, it’s a bit too huge. Take a look at the NPM (Node Package Manager) website. Chances are, if there’s a use case for it, someone has already written a library for it.
How do you install and use 3rd party libraries in Node.js?
You need to use the node package manager command line tool, npm. See here for a basic intro.
Isn’t Node.js single threaded by default? How can it handle heavy workloads?
Node’s I/O model is non-blocking. A Node process can continue executing code or listen for requests while I/O operations (such as disk, database or network calls) are executing asynchronously. For most real world workloads, this works fine. But in the case of truly CPU-intensive loads, there are ways to create multiple worker threads or balance the load across multiple Node processes.
Don’t forget:
Are there any popular frameworks for developing REST APIs and microservices using Node?
Express.js is currently popular, although there are other up-and-coming contenders.
If I want to learn more advanced Node programming?
Try this: https://books.goalkicker.com/NodeJSBook/