I'm trying to write a debugging framework for node.js and am having a hard time figuring out how to get the full path to a core module file like fs.js
.
I've heard it's in the /lib
folder of the node installation, but I'd need to get this from the code in a consistent way for a variety of install situations (including windows).
I've tried taking a look at the process
and process.env
values for something like a node install path but can't see anything that immediately pops out at me.
To find where the installed node executable is located you can look at the process.execPath which gives the absolute path to Node executable.
To find where a certain module is located you can use require.resolve(module);
However I think the global modules are not directly accessible from the filesystem as other regular modules since they seem to be cached somewhere within the executable.
1- create a file in the project root call it settings.js
2- inside this file add this code
module.exports = {
POST_MAX_SIZE : 40 , //MB
UPLOAD_MAX_FILE_SIZE: 40, //MB
PROJECT_DIR : __dirname
};
3- and any time you want your project directory just use
var settings = require("../settings.js");
settings.PROJECT_DIR;
in this way you will have all project directories relative to this file ;)