I am sure I am not alone when I say that I love node.js. The ability to create complex full stack web applications with a single uniform scripting language for both the front, and back end is really changing things for the better if you ask me.
I have already written a few posts on node.js based projects such as hexo, and grunt, I realize that I have jumped the gun sort of speak for not throwing together my take on node.js hello world examples. Although I am sure it has been done before many times sense it’s release in 2009, I thought I would throw my own together for the hell of it so here it is.
If the aim is to make back end scripts that ultimately spit 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.
Yes thats it, just save it as something like my_script.js with your favorite ASCII or Unicode editor then navigate to the working directory and just call it with node.
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.