Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pionl/zeit-pkg-path
Helps to resolve paths when using pkg (detects if using packaged app or testing via node cli.js) related to current working directory.
https://github.com/pionl/zeit-pkg-path
nodejs path pkg
Last synced: 10 days ago
JSON representation
Helps to resolve paths when using pkg (detects if using packaged app or testing via node cli.js) related to current working directory.
- Host: GitHub
- URL: https://github.com/pionl/zeit-pkg-path
- Owner: pionl
- License: mit
- Created: 2019-01-18T10:53:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-18T11:17:15.000Z (about 6 years ago)
- Last Synced: 2024-12-11T22:12:57.964Z (about 1 month ago)
- Topics: nodejs, path, pkg
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zeit-pkg-path
> **Node 8+**
Helps to resolve paths when using [pkg](https://github.com/zeit/pkg) (detects if using packaged app or testing via node cli.js) related to current working dir of running app (where the app is installed or where node was executed).
## Example
```bash
# Running in /root/
node test/cli.js
# Path returned via path.resolve('test.png')
# > /root/test.png# Running in /root/
node cli.js
# Path returned via path.resolve('test.png')
# > /root/test.png# Running in /root/test
./cli
# Path returned via path.resolve('test.png')
# /root/test/test.png
```## Install
```
npm install zeit-pkg-path
```## Usage
```javascript
// in context /root/test
const path = require('zeit-pkg-path')// Resolves path based on current base path
console.log(path.resolve('../index.js'))
// /root/index.jsconsole.log(path.join('index'))
// /root/test/indexconsole.log(path.isLocal)
// True if running via node index.js, false if running in packaged executable// Replaces base path from given string with dot to make it relative
console.log(path.toRelative('/root/test/index.js'))
// ./index.js// Returns the base path
console.log(path.paths.base)
// /root/test
```