This post contains content about Now 1.0 – Learn about the latest version, Now 2.0.
Now 2.0 - Upgrade Available

Node.js 8.0.0 has just been released and we have made it the default for all new Node.js deployments. With the new native support for async and await, deploying a microservice is now easier than ever before.

The stable 8.0.0 release is now the default runtime for all new Node.js deployments. If you want to lock in a particular version or range, you can use the engines field in your package.json (more).

What follows is a quick summary of the changes we are most excited about for our now users.


Native Async/Await and Promisification

For most of its history, Node.js asynchronous programming involved in one form of the other devising strategies for dealing with "callback hell". Almost exactly a year ago, we blogged about its eventual solution.

In anticipation for it, we created a tiny microservice framework called micro, that allows you to define a HTTP endpoint in terms of a simple function that takes in the request and response objects:

module.exports = async (req, res) => {
await authenticate(req)
await rateLimit(req)

return {
  users: await db.getUsers()
}
}

No need for middleware or next callbacks for flow control.

The service is simply a function that you can expose as an HTTP server with:

micro

Your function-microservice will be exposed as http://localhost:3000

Until recently, leveraging micro involved using an unstable --harmony flag or transpilation processes. Not anymore. To deploy a microservice like the one above, check out this example. All it takes is to define your start script and run:

now

To install now on your menubar and command line automatically, we recommend Now Desktop.

With Node.js 8.0.0 we are gaining the capability to turn any callback interfaces into Promise-returning APIs that can be awaited:


const fs = require('fs')
const util = require('util')

const readFile = util.promisify(fs.readFile)

module.exports = async function wannacry () {
const passwords = await readFile('/etc/passwd')
// …
}

Once we promisify readfile we can await it inside async functions

With async/await and util.promisify combined, we expect Node.js to become significantly more approachable to people who are new to asynchronous programming.


Reliable Logging

Until today, logging via console.log and console.error could fail and make your program crash. From a systems engineering standpoint, the ability to handle those errors is important. In the vast majority of cases, however, those very tools are used to help debug and report exceptional situations to begin with!

From Node 8 on, those errors will be ignored, avoiding potentially fatal crashes. As a reminder, now automatically captures stdout and stderr for you and shows them via our Web UI:

We interleave your application logs with proxy logs automatically for better contextual debugging

… or from the command line:

now logs -f -a <your-deployment-url>

The -f flag tails the logs in realtime, while -a (all) interleaves traffic logs.


DevTools Debugging

The debugging story in Node.js has been reduced to adding a simple flag:

node --inspect index

The new --inspect flag is all you need to add

… and then booting up Chrome and pointing it to about:inspect:

The Chrome devtools allow for step debugging, source code inspection and more

Node 8 also includes V8 Turbofan+Ignition, which speeds up the HTTP Server benchmarks by 10%!.


Conclusions

We are very excited to see Node.js become faster and more reliable. What's particularly noteworthy is that, contrary to the norm, its maturity has been matched by an impressive development pace.

We want to take this opportunity to congratulate the Node.js and V8 teams. We look forward to continue to expand its reach into the cloud.