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

relativistic-fs

v0.1.0

Published

fs wrapper to force relative paths

Downloads

7

Readme

npm

relativistic-fs

Build Status Dependency Status

fs wrapper to force relative paths everywhere.

Useful when you want to restrict your Node application to a certain directory. Absolute paths won't work because of executable bits on all the top-level directories, for example:

fs.readFileSync('/root/apps/my-fancy-app/foo/bar')
// Needs execute bit on:
//   - /
//   - /root
//   - /root/apps
//   - /root/apps/my-fancy-app
//   - /root/apps/my-fancy-app/foo
// Needs read bit on:
//   - /root/apps/my-fancy-app/foo/bar

With relativistic-fs (assuming /root/apps/my-fancy-app is the working directory):

fs.readFileSync('/root/apps/my-fancy-app/foo/bar')  // translates to ./foo/bar
// Needs execute bit on:
//   - /root/apps/my-fancy-app
//   - /root/apps/my-fancy-app/foo
// Needs read bit on:
//   - /root/apps/my-fancy-app/foo/bar

See?

relativistic-fs can be applied on the top level of your application and all the modules (incl. dependencies) will just work even on the most stringent permission system (provided they don't genuinely need to access files they lack a permission to).

API

rfs = require('relativistic-fs')

relativistic-fs exposes all functions from the core fs module under the same name and interface:

rfs.readdir(__dirname, function (err, files) {
  // ...
});

rfs.install()

Replaces the core fs module with relativistic-fs so that any subsequent require('fs') calls return rfs. (Modifies require.cache.)

Returns rfs.

Wrapped functions

Functions that are wrapped to transform path arguments:

  • access(path[, mode], callback)
  • accessSync(path[, mode])
  • appendFile(file, data[, options], callback)
  • appendFileSync(file, data[, options])
  • chmod(path, mode, callback)
  • chmodSync(path, mode)
  • chown(path, uid, gid, callback)
  • chownSync(path, uid, gid)
  • createReadStream(path[, options])
  • createWriteStream(path[, options])
  • exists(path, callback)
  • existsSync(path)
  • lchmod(path, mode, callback)
  • lchmodSync(path, mode)
  • lchown(path, uid, gid, callback)
  • lchownSync(path, uid, gid)
  • link(srcpath, dstpath, callback)
  • linkSync(srcpath, dstpath)
  • lstat(path, callback)
  • lstatSync(path)
  • mkdir(path[, mode], callback)
  • mkdirSync(path[, mode])
  • open(path, flags[, mode], callback)
  • openSync(path, flags[, mode])
  • readFile(file[, options], callback)
  • readFileSync(file[, options])
  • readdir(path, callback)
  • readdirSync(path)
  • readlink(path, callback)
  • readlinkSync(path)
  • realpath(path[, cache], callback)
  • realpathSync(path[, cache])
  • rename(oldPath, newPath, callback)
  • renameSync(oldPath, newPath)
  • rmdir(path, callback)
  • rmdirSync(path)
  • stat(path, callback)
  • statSync(path)
  • symlink(target, path[, type], callback)
  • symlinkSync(target, path[, type])
  • truncate(path, len, callback)
  • truncateSync(path, len)
  • unlink(path, callback)
  • unlinkSync(path)
  • unwatchFile(filename[, listener])
  • utimes(path, atime, mtime, callback)
  • utimesSync(path, atime, mtime)
  • watch(filename[, options][, listener])
  • watchFile(filename[, options], listener)
  • writeFile(file, data[, options], callback)
  • writeFileSync(file, data[, options])

What's up with the name?

relative-fs was already taken.

Install

npm install relativistic-fs

License

MIT