I am new to node.js, this is my first node application, so please excuse me if I ask the obvious question. I have a file called utils.js, and I need the functions defined in this file to be available in main.js. So I tried to give
require(utils.js)
But this throws me this error:
Error: Cannot find module 'utils.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
My main.jsis under c:\demo\proj\src\main\main.jsand utils.jsunder c:\demo\proj\src\utils\utils.js.
I tried below, requires a combination, but still I get can not find the module error:
Even I tried to put it in a folder node_modules, but still the same error. Can you kindly explain to me what I'm doing here?
Edit:
I tried changing the structure of my folder as @mithunsatheesh indicated, as shown below:
My require : require('./src/utils/utils.js')
node main.js, :
Error: Cannot find module './src/utils/utils.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)