path-locator

1.0.2 • Public • Published

path-locator

Build Status License Version

Locate files or folders in the directory where Node was started.

Install

Install locally:

npm install path-locator

Install globally:

npm install -g path-locator

Usage

Simply import the package and use the locate method:

var pathLocator = require('path-locator');
var path = pathLocator.locate('login.js');

directory

This property returns the full path of where Node was started.

var pathLocator = require('path-locator');
console.log(pathLocator.directory);
// /Users/name/projects/awesome_project/

locate(filename, [options])

Locate a file or folder using the filename parameter with an optional options object. It starts on the directory where Node was started and search recursively for the file or folder. It will return a string with the full path of the file in the file system or undefined if it didn't find anything.

This method runs synchronously.

Avaliable properties for options:

  • basePath: Adds a path to the main path to locate files or folders.
  • isFolder: Change the kind of source to locate. The default is false.
  • exclude: A list of folder to not search inside.
var pathLocator = require('path-locator');
 
console.log(pathLocator.locate('login.test.js'))
// /Users/name/projects/awesome_project/tests/login.test.js
 
console.log(pathLocator.locate('login.js'), { basePath: 'source/v1' })
// /Users/name/projects/awesome_project/source/v1/login.js
console.log(pathLocator.locate('login.js'), { basePath: 'source/v2' })
// /Users/name/projects/awesome_project/source/v2/login.js
 
console.log(pathLocator.locate('v2'), { isFolder: true })
// /Users/name/projects/awesome_project/source/v2
 
console.log(pathLocator.locate('login.js'), { exclude: ['source/v1'] })
// /Users/name/projects/awesome_project/source/v2/login.js

License

MIT License

Copyright (c) 2019 Ricardo Rauber Pereira

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i path-locator

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

12.6 kB

Total Files

9

Last publish

Collaborators

  • ricardorauber