javascript - How to reference files belonging to a module? -


i making module need use files, local module.

the path module can vary, depending on level of nesting , depending on whether if installed globally or locally.

how reference modules local files within module?

i found best solution:

for javascript libraries:

if javascript want include, can add relative path require call:

require('my-module/lib/other-script.js'); 

for other files open:

use module.filename obtain absolute path current file. remove file name , add relative path name it:

filename = module.filename.substring(0,module.filename.lastindexof("/"))+"/my/local/file.txt"; 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -