Error: Cannot find module 'dbconstant'

I have created a custom module whose functionality i want to export in other js modules, but while requiring the module i am getting the following error:

Error: Cannot find module 'dbconstant'

In file login.js i am doing following:

var dbConst = require('dbconstant');

which leads to error described above.

But when import the module using following code, it works fine:

var dbConst = require('/home/gaurav/mygitRepo/officemgmt/api/dbconstant');

login.js reside @ /home/gaurav/mygitRepo/officemgmt/api

I seriously doubt that giving absolute path is way to do this, if not, how can i import module.

Please put a comment if dbconstant code is also needed for analyzing the issue, i will add that too if required.

You can only import modules like that if they reside in node_modules, which is where scripts installed with npm sit, otherwise you have to use a relative or absolute path.

The following should work though, as long as either dbconstant is a folder with the main export residing inside an index.js file or the javascript file is called dbconstant or dbconstant.js.

var dbConst = require('./dbconstant');