On some systems, you can cache up to ~/.cache by creating a subdirectory to store your cache data, although it is much more common for applications to create a hidden directory in the users home directory. On modern Windows machines, you can create a directory in C:/Users/someUser/AppData . On Windows using a suffix . will not hide the file. I would recommend you do something like platform agnostic as follows:
var path = require('path'); function getAppDir(appName, cb) { var plat = process.platform; var homeDir = process.env[(plat == 'win32') ? 'USERPROFILE' : 'HOME']; var appDir; if(plat == 'win32') { appDir = path.join(homeDir, 'AppData', appName); } else { appDir = path.join(homeDir, '.' + appName); } fs.mkdir(appDir, function(err) { if(err) return cb(err); cb(null, appDir); }) }
Just declare a function to get the application directory. This should handle most systems, but if you are faced with a situation where it is not, it should be easy to fix, because you can just create some kind of alternative logic here. Suppose you want to allow the user to specify an arbitrary location for application data in the configuration file later, you can easily add this logic. At the moment, this should fit most of your cases for most Unix / Linux and Windows Vista systems and above.
Saving in the temp system folder, depending on the system, your cache may be lost in the interval (cron) or during reboot. Using the global installation path will lead to some problems. If you need this data to be unique for each project, you can expand this functionality so that you can store this data in the root of the project, but not in the root of the module. It is better not to store it in the root of the module, even if it is simply installed as a local / project module, because then the user does not have the opportunity to include this folder in his repositories, not including the entire module.
Therefore, if you need to save the caching data related to the project, you should do this in the root of the project, and not in node_modules . Otherwise, save it in the users home directory in an agnostic way to the system.