New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

root_require

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

root_require

Hijacks node's module resolution so that you can use a prefixed path to require modules from the project root.

latest
Source
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

root_require

Hijacks node's module resolution so that you can use a prefixed path to require modules from the project root.

If you want to accomplish this by transforming your code rather than using this runtime node hack, or for bundling for the browser, use babel-plugin-root-require.

install

$ npm install root_require

example

require('root_require').setRoot()

const myThing = require('~/things/relatively')

Starting from your project root, if you have a file lib/foo.js and you want to require it from routes/user/profile, you would normally write require('../../../lib/foo'). With root_require initialized, you can just write require('~/lib/foo') from anywhere.

api

setRoot(pathToRoot)

If no argument is given, setRoot will look for a package.json and consider the directory it is found in to be the root.

setPrefix(prefix)

The prefix to use to refer to the project root.

require('root_require').setPrefix('TATERS').setRoot()

require('TATERS/foo.js')

reset()

Restore module resolution to default behavior. You probably don't ever need to do this.

Keywords

require

FAQs

Package last updated on 04 Apr 2017

Did you know?

Socket

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