I write in the file like this:

module.exports.b2World = b2World; 

The file is called:

 D:\OpenServer\domains\td\lib\box2d\dynamics\b2World.js 

I'm trying to connect like this:

  this.express = require('express'); this.app = this.express(); var b2World = require('../../lib/box2d/dynamics/b2World'); var server = require('http').createServer(function (req:any, res:any) { }); server.listen(Server.Config.SERVER_SETTING.SOCKET_PORT); this.network = new Network(server); 

Only this connection does not work.

  var b2World = require('../../lib/box2d/dynamics/b2World'); 

Mistake:

Error: Cannot find module '../../lib/box2d/dynamics/b2World' at Function.Module._resolveFilename (module.js: 440: 15) at Function.Module._load (module.js: 388: 25) at Module.require (module.js: 468: 17) at require (internal / module.js: 20: 19) at Core.initialize (D: \ OpenServer \ domains \ td \ server.js: 562: 27) at new Core (D: \ OpenServer \ domains \ td \ server.js: 557: 18) at Object. (D: \ OpenServer \ domains \ td \ server.js: 572: 12) at Module._compile (module.js: 541: 32) at Object.Module._extensions..js (module.js: 550: 10) at Module.load (module.js: 458: 32)

  • Instead ../../ should be ./ - Dmitriy Simushev
  • You would decide: the file is not connected to you or it is still connected, but gives ReferenceError - Dmitriy Simushev
  • For each individual problem - a separate question! - Dmitriy Simushev
  • can prototype.js be connected via npm? - Serge Esmanovich Nov.
  • If it is in the npm repository, then you can - Dmitriy Simushev

1 answer 1

When resolving the path to the module, node.js uses the directory of the current file (in which the connection is made) as the base one.

Judging by the text of the error, you make the connection in the file:

 D:\OpenServer\domains\td\server.js 

If your library is in

 D:\OpenServer\domains\td\lib\box2d\dynamics\b2World.js 

the connection instruction should be:

 var b2World = require('./lib/box2d/dynamics/b2World'); 
  • Connect helped thanks, only the 2nd problem got out =) - Serge Esmanovich