Skip to content

Find a file by walking up parent directories (barebones implementation, no dependencies).

License

Notifications You must be signed in to change notification settings

paulovieira/find-up-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

find-up-sync

Description

Find a file by walking up parent directories (barebones implementation, no dependencies).

Useful to automatically find the path to configuration files that should exist in a predefined directory. See example below.

Install

npm install --save find-up-sync

Example

Assume your filesystem has a structure like this:

/
└── home
    └── pvieira
        └── my-app
            ├── config
                └── email-key.txt
            └── xyz
                └── abc
                    └── find-key.js

We want to obtain the path to config/email-key.txt from any module in the application, without using relative paths or any other dependency specific to the application (such as a global __rootDir variable).

The find-key.js module will find the path:

var FindUp = require('find-up-sync');
var path = FindUp('config/email-key.txt');

// path === '/home/pvieira/my-app/config/email-key.txt'

Related modules

About

Find a file by walking up parent directories (barebones implementation, no dependencies).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published