A simple Node file generator example

So way back I made a post on a simple node static web sever that is a subject that seems to come up now and then. Sense then I have not really continued with posts like that which have to do with making very simple versions of basic actual projects when getting started with node. than simple demo like scripts for just one little native method or npm package with nodejs development. So I thought it would be a nice change of pace to start making a few more posts like that, starting with this one that has to do with just making a simple file generator.

Read More

Using ANSI escape codes in nodejs

The use of ANSI escape codes is what can be used to control the format and behavior of a command line interface when making some kind of node cli tool. in node npm packages like chalk use ANSI escape codes to control the color of text, but they can be used to do far more than just that in the terminal. In this post I will be covering some basic examples of the use of ANSI escape codes to control things like the color of text, as well as cursor movement and more in nodejs.

Read More

Promise resolve and reject methods for just creating a resolve or rejected promise

When working with promises in javaScript there will come a time now and then where I just want to return a resolved promise without having to bother with the promise constructor to do so. In addition there is also doing the same but with a rejected promise, just retuning that inside the body of a promise so that is just directly results in a catch statement being called.Well luckily even with native javaScript promises there is the Promise.resolve, and Promise.reject methods that can do just that.

These resolve and reject promise prototype methods will come in handy often when creating a long chain of promises. When making long promise chains I often just want to return a resolve or rejected promise inside the body of a then of catch method call in the chain. It is basically a more appropriate alternative to using the promise constructor, passing a function with a resolve argument, and then calling resolve inside the body of that function that is given to the promise constructor. This kind of solution will work, sure but why bother doing that when I have the Promise.resolve method.

So todays post will just be on the Promise.resolve, and promise.reject methods.

Read More

Get an array of words from a string using Lodash or native javaScript AKA Lexical Analysis Tokenization

In lodash there is the words method that can be used to quickly preform lexical analysis tokenization of a string. In other words the lodash words method is used to split a string into an array of substrings where each substring is a single word from the given source string.

In some cases this could be easily done with the split method, but it is not always so cut and dry. There are text samples that might contain certain characters that are to be cut out or included in the process for example. So that being said there is a need for some kind of Tokenizer method that is better suited for the task of creating an array of words from a text sample.

The lodash words is one such method that seems to work okay, but there are other methods of doing this with plain old native javaScript by itself also. In addition if you really want to get into lexical analysis there are of course additional javaScript dependencies outside of lodash that are of interest when it comes to this. So with that said lets take a look at the lodash words method as well as some additional alternatives when it comes to getting an array of words from a string with javaScript.

Read More

node command line options and command use examples

This will be a post on the node command that is used to start nodejs projects written in javaScript. The node command is used to run scripts written in javaScript by way of an external javaScript file, or other means such as from the command line via the eval option. This post is mainly aimed at developers that are new to nodejs, but even if you are a more seasoned nodejs developer there might be a few more aspects of using the node command that you might not yet be aware of that might be of use in some situations when it comes to advanced topics such as piping).

Read More