Why you should really learn Node.js!
This is for Java and .NET developers wondering whether learning JavaScript on the back-end (i.e. Node.js) is worthwhile for their career.
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.
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.
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.
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.
A large number of companies, including Netflix, Microsoft, Amazon Web Services, Paypal, Uber, LinkedIn, Trello and eBay.
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.
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.
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.
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.
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.
You need to use the node package manager command line tool, npm. See here for a basic intro.
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:
Express.js is currently popular, although there are other up-and-coming contenders.
Try this: https://books.goalkicker.com/NodeJSBook/