node append file fs method

In nodejs projects file system management comes up a lot, and so does the act of appending a file that all ready exists rather than completely rewriting a file all together. The node append file fs module method is a file system method that can be used to quickly finish most tasks that have to do with creating a file if it does not exist, or just simply appending to the end of it if it does. A task that is common of most log files that have to do with just simply spitting out a recode or what is going on with something.

Read More

fs mkdir file system method in nodejs

So when it comes to making a new folder in nodejs there is the fs mkdir method that can be used to make a folder. If I just want to make a single folder at a given root folder, then the process of doing so is fairly easy with the core node file system module by itself.

There is however how to go about making a whole bunch of folders recursively just like that of the mkdirp command in posixs systems. When it comes to that I could use the child process module as a way to call that external command, but still there should be a way to do so in nodejs.

So in this post I will be going over the fs mkdir method in node in the file system module that can be used to create a new folder in nodjes, and branch off into some other related topics when it comes to making nested folders and so forth linking to other posts where doing so is called for when it comes to npm packages.

Read More

loash first method and related topics

The lodash first method which is also the lodash head method actually, is just a simple convenience method for getting the first element of an array that is passed to the method as the first argument. So then this is one of those methods in lodash that might make some question the worth of lodash a little when compared to just working with native javaScript by itself. After all getting the first element of an array with just native javaScript is just a matter of just grabbing at index 0 of the array with the bracket syntax. There is also the question of how to get the last element of an array, with this there is the lodash last method that does that, and again this is something that is not all that hard and often be done by just simply subtracting 1 from the length of an array to do so.

So maybe there are still a few things to write about when it comes to a method like the lodash first method, after all there is not just getting the first element of an array when getting the first element of an array. For example there is getting the first element of an array, and also mutating the array in place while doing so. There is trying to get the first element of an array, but getting a default value in the event that the first element of an array is undefined. There is also sorting an array before getting the first element, and when doing so mutating in place and not mutating in place.

So then in this post I will be going over a few quick examples of the lodash first method, and also a few additional topics that come to mind when preforming this kind of task. With that said I will be looking into some additional lodash methods that can be used to get the first element, as well as other typical elements of interest. Also there is taking a look at some additional examples that have to do with getting the first element of an array, and other related tasks using just native javaScript by itself.

Read More

New Buffers in nodejs the good bad and ugly

So when working with buffers in nodejs making a new Buffer in nodejs there are some things to be aware of. There is making a new buffer with the new keyword and what result that gives compared to the other options available in late versions of node.js. The quick and simple answer is that from what I have studied the use of the new keyword is something that should be avoided when creating buffers in nodejs, and other methods provided are what should be used to create them. However in order to really know why that is, some additional context is required.

In this post I will be going over in detail what the deal is with making a new buffer with the new keyword in nodejs, and why it is that you might want to not do that if you have the option to do so.

Read More

Nodejs write file method basics and more

The nodejs write method of the nodejs built in file system module will come up a lot when it comes to do anything with, well writing a file in nodejs. There is more that one method in the file system module that can be used to write data to a file system, but this is the one that I find myself using all the time over the others when it comes to quick simple projects.

There is the old way of how to go about using the nodejs write file method that can lead to a kind of call back hell, and then there is the more modern way of using write file that involves the use of promises and the util promisify method. I generally choose to use promises over callbacks because I use write file along with many other methods and I find that promises are a much better way of making many calls to methods like this in a certain order.

Read More