Linux echo command and scripting with nodejs

So this will be a quick post on using the Linux echo command and node.js when it comes to creating shell scripts with javaScript rather than the usual Bourne Shell. The echo command just simply prints something to the standard output, in some cases now and then I find myself using it. For example just simply piping in some kind of simple test input to a CLI tools standard input would be one reason why I would go about using the echo command. The test output that echo creates can be used as a place holder of sorts for input from something else that would prove to be a real use case scenario.

The echo command can have many real would use cases also though, for example when writing a bash script I might want to print some result in string form to the standard output when the script is called, one way to do so would be to use the echo command and pass that string value as the first argument. When doing so there are a number of options that can be used to set of there should be a line break at the end or not, or if some special characters should be used or not to create the final output.

So in this post I will be going over some basic example of the Linux echo command, and also go over some of the advanced options that often prove to be useful when using it.

Read More

Canvas save and restore methods for saving and loading canvas state

The canvas save 2d draw context method can be used to save the state of a 2d canvas drawing context. Once a context has been saved it can later be restored with the canvas restore method.

Because the canvas save method can be used to save a current state of a drawing context, it can come in handy when using other 2d context methods like canvas translate, and canvas rotate which are two that come to mind right off the bat when it comes to using the canvas save method. The reason why is because these are methods that mutate the state of a drawing context by way of delta values that are passed as arguments. These kinds of methods differ from methods that are used to set properties to given arguments or just simply setting properties. So the canvas save and restore methods are useful when using methods that mutate the drawing context in this way.

For example the canvas save method can be used to save the current state of the drawing context, and then changes can be made to the fill style, translations, and rotations. Something can then be drawn with this new mutated 2d drawing context state, and then put back the way it was with the canvas restore method once I am done drawing to it.

So in this post I will be going over some quick examples of the canvas save method, and may other related context methods to point out some reasons why the method is so useful.

Read More

The Node process exit method to end a node process

So there is the question of how to make a node process exit when it does not do so normally, and also how to go about setting some events that will fire when the process exits. In this post I will be going over the process exit method and well as exit codes, exit events, and other related topics that mainly have to do with the use of the process global.

When a process exits it often does so with an exit code. When using the main process.exit method it is possible to pass a code to let any additian scripts that might make use of what I am making know if the script exited as exspect with a code of zero, or if some kind of error happend with a code of one or higher. It is also possible to define some event handers that will fire when this process.exit method is called, or if for whatever the reason the process exits.

Read More

The Node URL Module for working with URLS in nodejs

In node js there is the path module that is there for working with file system paths, but there is also the node url module as well for working for web address urls. A url can consist of many parts inclusing the protocol such as https, the hostname, query string values and more. The url module has methods that can be used to quickly convert a url string to an object of these many properties. Also there are methods that can be used to format such an object into a url also, so lets look at some quick examples of the node url module.

Read More

Express stream and the XMLHttprequest on process event

So I am working on a express project in which I would like to stream to the client progress that is being made. I have some more demos to work out until I get a better grasp on what I want to go with, but have learn some great stuff in the process, about express streams. So it turns out that the response object in middle ware methods is a kind of stream and it inherits from the node http response method. So in express streams can be used by way of the response object to send data to the client in a chunk by chunk basis. In this post I will be going over some examples of how to do this, and how to check on progress on a request with the on process XMLHttpRequest event.

Read More