Socket
Socket
Sign inDemoInstall

global-path

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    global-path

Set Global Path


Version published
Maintainers
1
Install size
3.41 kB
Created

Readme

Source

:ghost: global-path

Set Global Path Elegantly. When you have directory structure with ugly nested depth it will bad for maintenance. Eureka, now you want to register your path globally.

Turn your code

const dbinit = require('../../../helpers/db/init')

Into this code

require('global-path')('helpers', '@/../../helpers/')

const dbinit = __helpers.require('db/init')

Installation

$ npm install global-path --save

or

$ yarn add global-path

Usage

You should register alias in your main file or in any file before require everything. @ symbol is an alias of __dirname. If you're use eslint you can call it via global.

// index.js
require('global-path')('config', '@/src/config/')
__config.require('myconfig')

// bin/cli with no prefix
require('global-path')('utils', '@/../src/utils')
console.log(utils.path, global.utils.path) // Print path
utils.require('string')

Params

globalPath (alias: string, path: string, prefix?: string)

License

MIT © oknoorap

Keywords

FAQs

Last updated on 02 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc