I'm developing a simple web search scope (since weridly enough I couldn't find one). anmd after creating the POC I noticed the the main JavaScript file is quite large and complicated.
is there any way to separate the main file to multiple files? I've tried with the Node.js require but all I get is an error that it can't find the module :
var templates = require('./templates'); // in order to include templates.js
All I get in result is:
module.js:338
throw err;
^
Error: Cannot find module './templates'
Anyone knows how to include a JS in the main scope JS file?
(Posted on behalf of the OP).
It seems that the answer was quite simple the "included" js file need to be under the node_modules directory and the require should not include current directory prefix ("./"). In other words the fix was to move the templates.js file under node_modules and change the code to :
var templates = require('templates.js');