However there is much more to that also, nodejs can also be used for all kinds of general programing tasks. For example I like making all kinds of useful and interesting command line interface tools with nodejs that ca be used to create files, walk over a file system structure, and so much more I do not event know where to begin.
However I guess you always need to start somewhere when it comes to node.js and the concept of a hello world example. in addition although I am sure it has been done before many times sense it’s release in 2009, I thought I would throw my own hello world examples together for the hell of it so here it is.
If the aim is to just make a script that just spits something out to the standard output of the console, then writing a node.js hello world can be as simple as just doing a single console.log call in a new text file, and then save it as something like my_script.js.
Yes thats it once that is saved as a file make the working directory the same as the location of the file and then just call node in the terminal passing the name of the file as the first argument to it like so
There is more than one way even to do just this, but the console log method gets the job done. The only draw back that comes to mind when using it to write to the standard output is that it will always write an end of line char to the end of the output, so another way would be to use process.stdout.write.
I often run into situations in which I want to write a module. Getting started with modules is pretty easy, I just need to append to exports like this.
Once I save this as a file that I often tuck away somewhere in my working tree. I just need to use require to use it in a script.
Many node.js projects are not just stand alone Command Line Interface tools, and modules. Typically a lot of node projects are some kind of full stack web application. Starting a little hobby project can begin with something as simple as this:
Be sure to check out my many other posts on node.js and npm packages.
Thats all for now, happy coding.