Buffers in node.js

When node.js was first developed there where no typed arrays such as Uint8Array to help work with binary data. As such Buffer was introduced to help work with binary data in a node.js environment. Buffers are something that I run into when working with streams, ether file io streams, or from http requests. In any case Buffers are helpful when doing anything that involves working with raw binary data. So lets take a look at some examples of buffers in node.js.

Read More

The node.js http module and setting up a simple web server with just native javaScript.

There are many frameworks that help to make the process of making a node.js powered full stack web application a quick process compared to working with just the core node.js modules. Frameworks like express, and hapi just to name a few.

I might prefer to use express when I make such projects, but still on occasion I find myself writing at least a few simple demos using just the node http module by itself without any additional framework on top of nodejs. This kind of approach may be a poor decision when it comes to making any kind of real serious full stack project when working on everything by oneself at least. The situation might be different when it comes to having a large team of people working on something, but even then it is going to be a lot more work, and there are going to be a lot of bugs.

Read More

Killing a node.js child-process that was started from within a main script.

In my effort to make helpful posts on node.js, I have been working with the child_process module lately. This is a very useful module that can be used to launch a command on the operating system of the computer that the node.js project is running on, including node itself. However the child process module should for the most part be used to call external commands outside of node, as there are many other options when it comes to running a script more than once when it comes to javaScript code.

So methods in the child process module like spawn and exec are ways in which I can run another script, or command outside of node, from within a script. When doing so this child process will end up having it’s own process id, and is a way to go about doing some things in parallel in a node.js environment.

When launching such a process there might be some kind of condition in which I will want to kill the child process if it is the kind of process that will keep going otherwise. Luckily doing so is very easy I just need to use the kill method that is provided to the object that is returned when using a child process module method like spawn. So in this post I will be quickly going over the basics of killing a process in nodejs.

Read More

The node.js child-process module

So for February I was plaining to expand my catalog on node.js related content by getting into writing a bunch of demos on core node.js modules, rather than what I have been doing for the most part before hand which is writing about npm packages. Looking over what I have so far, I never got around to writing about the child_process module yet, so I thought I would give that one a go.

Read More