Node.JS

New Book: Asynchronous JavaScript with Promises, Generators and async/await

es-2015-16-17-promises-generators-and-async-await-2-1000.jpgThe JavaScript language is changing, and among the changes are three new features which will revolutionize the way we wri

Asynchronous array operations in ES7 JavaScript async/await functions

A glaring problem with the most excellent async/await feature in JavaScript is all the existing coding structures that only work with synchronous code. In an async/await function it's trivially easy to write a simple "for" loop that contains whatever async/await calls you want. But as soon as you try "Array.forEach" with an async callback function it will fail miserably. That's because this function, like so many existing interfaces which take a callback function, assumes the callback is synchronous.

Useful reading to understand the Promises, Generators and the async/await feature for Node.js/JavaScript

The long-awaited async/await feature for JavaScript promises to make our lives much easier. Instead of asynchronous JavaScript programming being tricky and error-prone, with async/await our code will look like regular synchronous code we write in other languages, but will accommodate asynchronous code execution while retaining the single-threaded nature of JavaScript.

Asynchronous Node.js/JavaScript programming with Generators and async/await

The advent of async/await for Node.js - Node.js v7 has now arrived: The long-awaited day has arrived when we can begin to use async/await in JavaScript without jumping through crazy hoops. In Node.js v7 we just run our code with a command-line option, and voila we can use async functions.

Memory-efficient CSV transformation in Node.js

nodejs-dark.pngThose of us who consume/edit/modify/publish CSV files must from time to time transform a CSV file. Maybe you need to delete columns, rearrange columns, add columns, rename volumes, or compute some values taking one CSV file and producing another. In my case, I have a raw CSV file with no column headers that's organized in a way which makes sense for one team in our company, but we need that same data organized a different way, with different column names and containing selected fields.

The advent of async/await for Node.js - Node.js v7 has now arrived

nodejs-dark.pngWith today's first release of Node.js version 7, we now have async/await as a base feature of the platform. This is a significant milestone that wasn't even mentioned in the commit message. The async/await feature is so important that I'm preparing a short book to discuss JavaScript asynchronous programming patterns, that highly features async/await.

Click here for more Node.js programming advice

Make a bash script detect the directory it's stored in, to access data there

You may need to write a bash shell script that accesses data stored alongside the script, while your current working directory might be elsewhere. In my case the shell script needed to use Node.js scripts stored next to the shell scripts -- the shell script acting to simplify running the Node.js scripts. The "data" to be accessed in this case is the Node.js scripts, plus the support modules required to run them. You may have other data like a list of hostnames or who-knows-what.

The basic outline is

Node.js adoption -- why use Node.js

How do you choose between Node.js or other web application technologies? There's lots of web application development platforms out there now, why do you use Node.js. The wrong answer is "because it's cool".

Node.js programming tips

Safely detect if a Node.js module is installed before using require() to load it: Normally you just use "require" to load a module. Sometimes you need to first check the module is available, to avoid an error if it isn't, or to print a useful error.

Pages