Build your nodeJS Application in a modular way

Now a days almost all web services or integrations are done on top of nodeJS run-time. NodeJS is a flexible platform with lot of community support. Even it is possible to create documents like xlsx, docx or pdf directly from nodeJS. All major cloud platforms uses nodeJS as their level 1 language.

Modularity

NodeJS by design achieves the modularity by using the node_modules structure. All the required modules are stored in node_modules directory and we can invoke the modules any where in our code.

But are we using this modularity in our application code. Most of the application I saw contains a lib folder, i which we store all js files . This js files are imported in the required areas using relative paths.

 

The main problem with this kind of approach is that when we change the path of a service file the path to the db should change. Also the format is not readable. We will be confused with the file’s authenticity.

The Solution

A much better approach is to design our application as modules, such as db , logging, error etc . Lets say your application name is cms, then it is much easier to represent the module using scope

 

 

You can develop the modules separately and publish in to any NPM servers ( public / private ) and use it as like any other module.

If your application needs the logging module

 

If you don’t want to split your application in to bits and pieces, there is another approach.

A more better way

Keep the modules that you want inside a separate folder. Lets say “@cms”. Use separate folder for each module and let the modules have a separate package.json. This way it will become a valid node module.

The package json for the modules will look like this

 

Once the modules are ready now its time to do some scripting. Add the install.js in the “scripts” folder.

 

Add this script to your main package.json.

 

The script will be executed every time you do npm install. So once all other node modules defined in the dependencies are installed, it will create a link from the @cms folder outside to the @cms folder inside node_modules. So any changes you make to the outer @cms folder will be reflected to the folder inside node_modules.

 

You can see that the symlinks are installed for @cms. This is not a shortcut file rather that hard links created using “ln” in linux.

node_modules folder
@cms folder is along with other npm modules in the node_modules directory

Inside @cms you can see our modules which is defined in the outer @cms folder

The modules inside @cms scope

This way you can achieve modularity. “@cms” folder is part of your source code. You can then import the required modules in the normal way.

When you want your application to execute run “npm install” followed by “npm start“.

This approach helps me in making the application more modular and extensible. Let me know your thoughts on this.

Linux Driver for BSNL Evdo


EVDO Client on Ubuntu 10.04
EVDO Client on Ubuntu 10.04

In most sites and forum i found some tedious steps to make the evdo work in linux. lot of scripts.

Making evdo workable in linux is very simple …
Goto http://www.ztemt.com/ennewzte/service/ziliao.action

and there download the appropriate version, install it.
Now you are having the dialer with you . Input the username and password in the options / setting window of the dialog , then click on connect button .. Bingoo ..

Immediate Shutdown in Windows

Usually windows will take 30 to  2 mins to shutdown the system .. Here is a tip that will give us the power to shutdown immediate a windows system . “Just like switching off a bulb

To do this , open the task mananger by pressing CTRL+ALT+DEL .

TaskManager
TaskManager

Then Click on the shutdown menu ..

after that click on the Turn Off Menu By Pressing Ctrl Button , then click ..

ShutDown Menu - Taskmanager
ShutDown Menu - Taskmanager

You can see that the system will turn off immediately… when u switch on the pc you will find that there is not scandisk , or any checks comming up .. .I am oing this .. and found no probs .. The same is applicable to the hibernate link in the shutdown menu …

experience the fastest Shutdown 😀