Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vitalics/node-basedir
node-basedir package available on npmjs.com
https://github.com/vitalics/node-basedir
absolute-path-provider base-dir js node npm package path-provider path-resolver
Last synced: about 1 month ago
JSON representation
node-basedir package available on npmjs.com
- Host: GitHub
- URL: https://github.com/vitalics/node-basedir
- Owner: vitalics
- License: mit
- Created: 2018-01-22T12:17:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-25T05:06:46.000Z (about 1 year ago)
- Last Synced: 2024-08-08T22:18:39.080Z (3 months ago)
- Topics: absolute-path-provider, base-dir, js, node, npm, package, path-provider, path-resolver
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/node-basedir
- Size: 14.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# node-basedir
### this package fix require path hell like this `../../../../etc`in your config write
``` js
require('node-basedir').register('')
```or just write on `packaje.json` file
``` json
{
...
"baseDir": "examples",
...
}
```## usage
```
-examples
|--some-path
| |--index.js
| |--somefile.js
|--test.js
```
``` js
// examples/somfile.js
class SomeClass {
someMethod() {
return 5;
}
}module.exports = SomeClass;
// examples/index.js
const SomeClass = require('./somefile'); // is equal for const SomeClass = provider('some-path/somefile');module.exports = { SomeClass };
// test.js
require('node-basedir').register('examples') // if in package json not set baseDir value
const { provider } = require('node-basedir');
const { SomeClass } = provider('some-path');
let someClass = new SomeClass();
console.log(someClass.someMethod());```
## run this example
`node -r node-basedir examples/test.js`
and return result is``` cmd
5
```