npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

basedirs

v2.0.1

Published

Get the appropriate base directory paths for the current OS

Downloads

12

Readme

basedirs

Get base directory paths appropriate to your OS.

Specs

Precedent

Usage

cachedir

cachedir(): string | null
cachedir(appName: string): string | null

Returns the path for user-specific non-essential (cached) data. Examples include servers with cached response data or applications using ephemeral data retrieved from the internet.

If appName is given, a path specifically for that app is returned.

If called on an unsupported platform, null is returned.

import { cachedir } from 'basedirs'

console.log(cachedir()) // `$HOME/.cache`, `$HOME/Library/Caches`, or `%LOCALAPPDATA%`
console.log(cachedir('App Name')) // `$HOME/.cache/app-name`, `$HOME/Library/Caches/App Name`, or `%LOCALAPPDATA%\App Name\Cache`

configdir

configdir(): string | null
configdir(appName: string): string | null

Returns the path for user-specific configuration files. Examples include application preferences or settings for CLI apps.

If appName is given, a path specifically for that app is returned.

If called on an unsupported platform, null is returned.

import { configdir } from 'basedirs'

console.log(configdir()) // `$HOME/.config`, `$HOME/Library/Preferences`, or `%APPDATA%`
console.log(configdir('App Name')) // `$HOME/.config/app-name`, `$HOME/Library/Preferences/App Name`, or `%APPDATA%\App Name\Config`

configdirs

configdirs(): string[] | null

Returns the paths for non-user-specific configuration files.

If called on an unsupported platform, null is returned.

import { configdirs } from 'basedirs'

console.log(configdirs()) // `['/etc/xdg']`, `['/Library/Preferences']`, or `['%ALLUSERSPROFILE%']`

datadir

datadir(): string | null
datadir(appName: string): string | null

Returns the path for user-specific data files. Examples include saved game files, mail client databases, or chat client log storage.

If appName is given, a path specifically for that app is returned.

If called on an unsupported platform, null is returned.

import { datadir } from 'basedirs'

console.log(datadir()) // `$HOME/.local/share`, `$HOME/Library/Application Support`, or `%APPDATA%`
console.log(datadir('App Name')) // `$HOME/.local/share/app-name`, `$HOME/Library/Application Support/App Name`, or `%APPDATA%\App Name\Data`

datadirs

datadirs(): string | null

Returns the paths for non-user-specific data files.

If called on an unsupported platform, null is returned.

import { datadirs } from 'basedirs'

console.log(datadirs()) // `['/usr/local/share', '/usr/share']`, `['/Library/Application Support']`, or `['%ALLUSERSPROFILE%']`

datalocaldir

datalocaldir(): string | null
datalocaldir(appName: string): string | null

Returns the path for user-specific data files that will preferably not be transferred to other machines with the same user account.

If appName is given, a path specifically for that app is returned.

If called on an unsupported platform, null is returned.

import { datalocaldir } from 'basedirs'

console.log(datalocaldir()) // `$HOME/.local/share`, `$HOME/Library/Application Support`, or `%LOCALAPPDATA%`
console.log(datalocaldir('App Name')) // `$HOME/.local/share/app-name`, `$HOME/Library/Application Support/App Name`, or `%LOCALAPPDATA%\App Name\Data`

executabledir

executabledir(): string | null

Returns the path for user-specific executable files.

If called on an unsupported platform, null is returned.

import { executabledir } from 'basedirs'

console.log(executabledir()) // `$HOME/.local/bin`, `$HOME/Applications`, or `%LOCALAPPDATA%\Programs`

homedir

homedir(): string | null

Returns the path for user files in general.

If called on an unsupported platform, null is returned.

import { homedir } from 'basedirs'

console.log(homedir()) // `$HOME` or `%USERPROFILE%`

runtimedir

runtimedir(): string | null

Returns the path for user-specific runtime files and file objects. This includes sockets and named pipes, but not other temporary files.

Only supported on Linux. If called on an unsupported platform, null is returned. May sometimes return null even on Linux.

import { runtimedir } from 'basedirs'

console.log(runtimedir()) // depends on the specifics of the Linux system