Running Node.js app as a service forever

When you start a Node.js server simply using node app.js, the server stops as soon as the shell session is killed. But if you want to keep you server running, as a server would naturally should, you need some way to keep the server proc alive.

Forever is seemingly a popular choice for running a server, as the name suggests, forever; or technically as long as you want.

While trying to install Forever, globally, via npm, it was complaining about the version number of inherits. So I did:

sudo npm install inherits -g

and then did:

sudo npm install -g forever

You are ready to run a nodejs server forever. Hence, do this:

 forever start --minUptime 1000 --spinSleepTime 1000 app.js

To make sure your new service is up

forever list

And if you want to stop, use

forever stop <PID/PID>

Node.js server on Azure

It is easy to use Node.js on a CentOS VM running on Azure, or any other linux VM on Azure. You can simply yum (with EPEL) install Node.js. Then an easy way to check if everything is working fine, a good idea is to test running a server from node. I am using this simple snippet:

var http = require('http')

var server = http.createServer(function (req, response){
  response.writeHead(200, {"Content-Type":"text/plain"});
  response.end("Hello World");


Now you can start it by typing

node app.js

To access this server that you just started, you need to access this port. This server is listening to port 8080. So you need to enable an endpoint on you Azure VM. Go to Microsoft Azure > yourazurevm > Settings > Endpoints and click add.
Then set following:
Endpoint: Any name (e.g. Http 8080)
Protocol: TCP
Public port: 8080
Private port: 8080

Now, hit okay and wait for the VM to enable this endpoint (a.k.a. port).


After this is enabled, you can now go to and see hello world.

List methods from a source file

Sometimes source files can become quite large. This is common mostly in C. But this may happen in other languages too. It makes working with these files particularly hard. Off-course there are IDEs which lists method and properties and what not. But there is a fun way to do the same stuff using python. The regex for the signature of Java methods is, (public|protected|private|static|\s) +[\w\\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;]) You can use this regex in python and have some fun summarizing your Java source files. Here is the script: on Github and via Gist, Cheers!

CLI package installation on Cygwin

Cygwin officially gives a vague answer about where there is a command-line installer for it or not. A quick search gave two options: cyg-apt (last updated in 2009) and apt-cyg (currently maintained). I’d try apt-cyg.

lynx -source > apt-cyg
install apt-cyg /bin

And you are all set.
If you do not have wget, install it.

apt-cyg install wget


(Failed attempt to) Set up Flow (Static typechecker for JS) on Windows 8.1

Flow is not officially supported on Windows. So I’m trying to set it up on my machine.

Flow uses OCaml; it is easy to get OCaml on Windows with Cygwin. Even the Cygwin setup has option to select OCaml.

First git clone flow from their source: using

git clone

Failed with error: ‘i686-w64-mingw32-gcc’ is not recognized as an internal or external command,
operable program or batch file.

Let us try by installing it

apt-cyg install mingw64-i686-gcc-g++

Retried make and got error: fatal error: gelf.h: No such file or directory

Try installing libelf

apt-cyg install libelf-devel

no luck yet.

apt-cyg install ELFIO

Yet after not getting any success, I tried installing the sources for lib-elf as well.
Not working.

Uninstall OCaml and try using Cygwin’s OCaml


looks better, but still getting err: can’t find sys/syscall.h
hack (part of hhvm/hphp) is system dependent. probably it’ll take more time getting it done.

Update: Right now there is an unanswered question on Quora about it; if you find a solution, please post.

Setting up NODE_PATH for using global packages via require(…)

Node.js intends global install for applications only. If you want to use some package in your project via require('...') the recommended way is to put them in projects root. However, you may want some packages to install globally via npm install -g package and use them on your node projects. Then, you have to make sure you have the %NODE_PATH% system variable set up to point global node_modules directory, e.g.: %USERPROFILE%\AppData\Roaming\npm\node_modules for Windows 8.