nodejs TypeScript and Node.js EventEmitter Take 2 This is take-two of articles on creating type inference for Node.js EventEmitters with TypeScript. This version provides a much cleaner interface for restricting events and handlers to those desired by your custom EventEmitter. So without further ado... The first step is define an
nodejs Async Event Emitter Pattern This is a short article that formalizes a pattern I've used in other articles: that is encapsulating an event emitter within a Promise. I dub this pattern the Async Event Emitter Pattern. While I won't go into the full details on EventEmitter class, I
nodejs Node.js AsyncGenerators for Streaming In a previous article I discussed using Generators for streaming data back to the caller. The Generators function is a synchronous function that allows lazy iteration over a collection of items as the caller requests them. Even though the standard Generator is synchronous, as
nodejs Node.js Generators for Streaming The concept of Iterators and Generators have been in JavaScript for a while now. This article will discuss how you can use a Generator to efficiently stream data to a consumer. Generators are a mechanism for creating and returning enumerable data (e.g. an
nodejs ChaCha20-Poly1305 AEAD with Node.js Since Node v11.2.0 was released we can now use ChaCha20-Poly1305 as an AEAD cipher! However, if you search for ChaCha20 on the crypto documentation page, you will find nothing. This article is a quick guide on how to use chacha20-poly1305 AEAD and
nodejs Simple Semaphore in Node.js A semaphore is concurrency construct that is used to limit or throttle access to a resource. This article shows a simple semaphore class in Node.js that can be used to limit execution of functions. Usage of the class looks like: // create a semaphore
nodejs Extending TCP Socket in Node.js One of the things we frequently do, but probably don't think about, is sending and receiving TCP data. Many of the packages we frequently use are using TCP sockets under the hood to connect to databases, remote services, and other devices on the network.
nodejs Out of Order Reads with Node.js Stream If you are not careful with a readable stream in paused mode, you can read data out of order. This post discusses how to properly read data from a readable stream in paused mode. First, a quick lesson on readable streams in paused mode.
nodejs Node.js Socket Backpressure in Paused Mode As a lot of these articles go, I was curious about something and could not find the answer online. In this case, how a Node.js Socket in paused mode handles back pressure from a client that attempts to write a large amount of
bitcoin Bitcoin P2PKH Transaction Building with Node.js This post discusses the mechanics of transaction building for Pays to PubKey Hash (P2PKH) transactions. P2PKH transactions are a standard format to pay to Bitcoin addresses. If you are unfamiliar with this type of transaction, I recommend reading through the transaction section of the
nodejs Big number JSON parsing with Node.js Take a look at this abomination of JSON: { "status": "ok", "ch": "market.btcusdt.trade.detail", "ts": 1530026484015, "tick": { "id": 10539491734, "ts": 1530026483694, "data": [ { "amount"
nodejs Field Descriptions in GraphQL with Apollo Server This article will discuss two techniques that can be used to descriptions to your objects and fields in GraphQL when working with Apollo Server Apollo Server makes use of the graphql-tools project to assist with schema building. It uses a simplified syntax to construct
nodejs Reading binary data with Node.js This article will discuss some of the basics required to work with binary data in Node.js. It will provide some of the basics required to work with Bitcoin at a low level using Node.js. Basics The first thing we'll get out of
nodejs Serial Promise Execution with JavaScript This article will discuss executing promises serially (wait for one to complete before moving on to the next). This is an extremely common pattern if you are inside of a loop and want to process something one at a time. For instance some how
nodejs Client Certificate Connections with Node I wanted to create a secure connection between two servers using TLS. The design has a server with a self-signed cert that requires clients to connect with their own client cert. This restricts connects to only clients that have a pre-shared cert. To make
nodejs HTTP GET Requests with Node This series of posts catalogs basic functions in Node via the built-in APIs. There are many libraries that provide syntactic sugar over these functions. However, it's a good exercise to understand how to do them manual. As serverless architectures increase in popularity, for performance
nodejs Node multipart/form-data Explained I was recently working on a project that involved sending large amounts of data through a series of HTTP based web service. After running through various scenarios to optimize throughput of these services we landed on using multipart/form-data to transmit data between our
express Increase request timeout for Express Apps In working on a Node.js microservice that had some long-running queries, I needed a way to increase the request timeout for the Express application. This isn't documented well, if at all, in the Express documentation so here's how you do it. Simply put,
nodejs Service-to-service Google API calls with Node I'm going to walk you through the steps needed to make a service-to-service request from Google API. In this example, I wanted to read Google Product Feeds and create one if necessary. This was all happening on a web server and I did not
nodejs Bulk Insert into Temp Tables with node-mssql One of the fastest pattersn for pushing data into MSSQL that we've found is using bulk copy. The process we use is bulk copy to push data into a temp table, then execute a stored proc to migrate the information into permanent tables. I've
design patterns Chained callback pattern in Javascript Imagine we have four methods a(next), b(next), c(next), d() where the first three accept a callback. We want to execut these methods in order, so that a completes and calls b, b completes and calls c, and c completes and calls
nodejs Reload module with Node.js require In Node.js using require to load a module will cache the result. If a module exports a constructed object it will be treated as a singleton, meaning it will only be constructed once While this is useful and performant for your application, it
nodejs Retain tty when using child_proces.spawn In trying to use child_process.spawn to launch a series of script files, I was running into an issue getting the child processes to render their progress. Normally, and as per the documentation for spawn, you can attach to the child process by
javascript Testing async/await with Babel and Mocha I was curious about testing ES6/7 code transpiled with Babel. Getting it to work is fairly straightforward. Here's what I found... Setup The documentation for Babel tells you to setup an NPM script to run mocha tests as such: { "scripts": { "
javascript Gettings started with Babel and Node I've been using Babel recently to perform transpiling of Node.js code. I've previously used Traceur and it always left a bit to be desired. The big winner now, is the support of ES7 code such as async/await. This guide will show a