logpath
A simple module to get a custom node.js app log dir path across platforms
Install
$ npm install --save logpath
Use
const logpath = require('logpath');
const logDirPath = logpath.createAndGetLogDirPath();
logpath creates directory if not found and tries to return log directory paths in the following order:
On Linux
/var/log/${APP_NAME}
${XDG_CONFIG_HOME}/${APP_NAME}
${HOME}/.config/${APP_NAME}
${XDG_DATA_HOME}/${APP_NAME}
${HOME}/.local/share/${APP_NAME}
On MacOS
${HOME}/Library/Logs/${APP_NAME}
${HOME}/Library/Application Support/${APP_NAME}
On Windows
${APPDATA}/${APP_NAME}
${HOME}/AppData/Roaming/${APP_NAME}
Where ${APP_NAME} is the name of the application using logpath, retrieved from package.json
Default
On any other platform, or if the directory path could not be returned (e.g. due to lack of read/write privileges), logpath will try and create a logs
dir
under the application's root folder.