Node.js cannot require a .js file in the same directory Node.js cannot require a .js file in the same directory node.js node.js

Node.js cannot require a .js file in the same directory


This is because, when you run you app (main.js) using node-webkit the root (working) directory is where the index.html is in, so './' refers to that directory not the one in which the file you requesting the module from is in.

You can easily solve this problem by using resolve method in 'path' node module and provide the output from it to the require method in your working file

Simply do the following:

var path = require('path');var updater = require( path.resolve( __dirname, "./updater.js" ) );

EDIT : info on global node object '__dirname' (and others) can by found here.