npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Best practice - where to store data for global package?

Hi where.
Where to store data for global package? If i store file in package directory - it is deleted on update


If I understand you correctly your package needs to store some data locally for re-use later.

Typically you let the user provide a location (directory or file) where the data should be written to.


If you’re talking about config files, there are standard places for storing program data on each OS. I use these settings in my package:

const { platform, homedir } = require("os")

const configBasePath = {
  linux: ".config",
  darwin: "Library/Preferences",
  win32: "AppData/Roaming",
}

const configDirPath = path.join(homedir(), configBasePath[platform()], "your-package-name")

const configFilePath = path.join(configDirPath, "your-package-name.json")