Ich denke nicht, dass das so einfach ist wie Sie hofften, aber mit dem Objekt können Sie dies tun:
// Load up some modules
var _ = require('lodash');
var natural = require('natural');
// These are where Node will go looking for the modules above
console.log('Paths:');
console.log(require.main.paths);
// You can print out the id of each module, which is the path to its location
console.log('Module IDs:');
require.main.children.forEach((module) => {
console.log(module.id);
});
Ausgang:
$ node index.js
Paths:
[ '/Users/tyler/Desktop/js_test/node_modules',
'/Users/tyler/Desktop/node_modules',
'/Users/tyler/node_modules',
'/Users/node_modules',
'/node_modules' ]
Module IDs:
/Users/tyler/Desktop/js_test/node_modules/lodash/lodash.js
/Users/tyler/Desktop/js_test/node_modules/natural/lib/natural/index.js
Soweit ich die Modul-IDs sagen kann, werden in der Reihenfolge sein, dass Sie require
ihnen, so sollten Sie für dynamisch, was auch immer Sie durch die Modul-IDs mit ihren Indizes arbeiten können oder suchen sind auf der Suche nach.
Suchen Sie im Online-PHP-Handbuch nach realpath(). :-) –