I am Hack Sparrow
Captain of the Internets.

Archive for Node.js

Scripting a Node.js App

What in the world could "Scripting a Node.js App" mean? Well, we are talking about the ability to write scripts for your Node.js apps. Wouldn't it be cool to be able to write independent JS scripts and execute them on the fly, in your app? This post is about that ability. When I first encountered the Node.js vm (Virtual Machine) module, I thought, "Hmmm, this thing looks like eval(). How different is it from ev ...

vhost in Express.js

Wondering how to replicate the Apache , it allows a web server to listen on a single port and serve different web apps depending on the domain name or the subdomain. Implementing such a feature in Express.js is very easy. Before we can see how is implemented in Express.js, we would need to play a little trick on our PC: [code] $ sudo vi /etc/hosts [/code] Append these entr ...

How to write Node.js Modules

So you have come to the stage where you feel the need to write Node.js modules of your own, or maybe you are just ... curious? Whatever be your reason, in this tutorial, I will show you how to create Node.js modules. Node.js modules are CommonJS-compliant modules, and are pretty straightforward to implement. You would have created a few modules by the end of this tutorial, trust me. First let's see how a Node module installed via NPM ...

Node.js Tutorial

Hello there! I see you wanna learn about Node.js and are looking for a tutorial to help you get productive in it immediately. Great news: you have come to the absolute right place. There exist many tutorials already on Node.js, written by knowledgeable and skilled people, on many websites. So what’s the point of writing another one? Well, those tutorials, even though informative, do not teach the basics of what Node.js is and the stuff that make it up. Instead of focussing on how to create ...

Global Variables in Node.js

So you are working with a set of Node modules, maybe a framework like Express.js, and suddenly feel the need to make some variables global. How do you make variables global in Node.js? The most common advice to this one is to either "declare the variable without the var keyword" or "add the variable to the global object" or "add the variable to the GLOBAL object". Which one do you use? First off, let's analyze the global object. Open a te ...