Try changing require
to start with your current directory explicitly, by adding ./
to the beginning of your path:
var cc = require("./crawler/leboncoin/lbcCrawler.js");
Otherwise, node will look in a node_modules directory, or similar, cf: http://www.bennadel.com/blog/2169-Where-Does-Node-js-And-Require-Look-For-Modules-.htm
EDIT:
For some reason, that's not working in node-webkit, but this might do the trick:
path = require('path');
var cc = require(path.join(process.cwd(),"js/crawler/leboncoin/lbcCrawler.js"));
EDIT2:
I think I've got it figured out now. __dirname
and __filename
are not defined in the node REPL, nor in a node-webkit script tag, even if your script tag is used to include your .js file, as in
<script src="js/app.js"></script>
Thus, if you call require lbcCrawler.js
from app.js
you'd need to require it as
var cc = require("./js/crawler/leboncoin/lbcCrawler.js");
because the path is where you start node-webkit, e.g. where index.html lives.
However, if you do
<script>require('js/app.js')</script>
then __dirname
and __filename
are defined and require
will search from where the app.js file lives, i.e. you would do:
var cc = require(path.join("./crawler/leboncoin/lbcCrawler.js"));
Because of this discrepancy, you might be better off depending on the value of process.cwd
(as in the first edit above) which should be the same in either case, whether app.js is included via require
or script
.