javascript - Preventing relative require calls from modules in a specific folder -


this sound odd, i'd modules in specific directory able require resources out of node_modules , not other part of application.

in specific directory:

  • require('fs') -- should work
  • require('../../something') -- denied
  • require('./another') -- denied

is remotely possible in node?

you make module that'll act require-proxy:

module.exports.require2 = function() {     if (arguments[0][0] !== '.') {         return require.apply(this, arguments);     } else {         throw new error('can\'t require relative modules');     } } 

of course, opt-in developers:

var require2 = require('require2'); var fs = require2('fs'); //everything's var fss = require2('./fss'); //throws error 

kind of similar idea thlorenz's proxyquire.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -