3.1.0 • Published 1 year ago

parent-module v3.1.0

Weekly downloads
14,351,680
License
MIT
Repository
github
Last release
1 year ago

parent-module

Get the path of the parent module

Node.js exposes module.parent, but it only gives you the first cached parent, which is not necessarily the actual parent.

Install

npm install parent-module

Usage

// bar.js
import parentModule from 'parent-module';

export default function bar() {
	console.log(parentModule());
	//=> '/Users/sindresorhus/dev/unicorn/foo.js'
};
// foo.js
import bar from './bar.js';

bar();

API

parentModule(filePath?)

By default, it will return the path of the immediate parent.

filePath

Type: string\ Default: __filename

The file path of the module of which to get the parent path.

Useful if you want it to work multiple module levels down.

Tip

Combine it with read-pkg-up to read the package.json of the parent module.

import path from 'node:path';
import {readPackageUpSync} from 'read-pkg-up';
import parentModule from 'parent-module';

console.log(readPackageUpSync({cwd: path.dirname(parentModule())}).pkg);
//=> {name: 'chalk', version: '1.0.0', …}

import-fresh@huyhpham/rn-linearchetype-libraryeasy-select-rnvuedragdropuploadimagesreact-native-bluetooth2killi8n-react-native-fast-imagepipihome@icanpm/api-master@oneplanetcrowd/developers@almeidaa/msreact-native-template-rfbaseairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@steven-torres/jsxr@fundefund/funde_ck@ntt_app/react-native-custom-notificationreact-native-covid-sdkgql_din_modbitgetafryxicons@jttechnic/interpreter@eginnovations/eginnovations-capacitor-plugin@drivetribe/dd-trace@saeon/quick-form@iobroker-community-adapters/iobroker.device-watcherprotogen-fb@olivervorasai/slidermysql-formatreact-native-printer-brothersneato@belko.tech/belko-multi-wallet-sdk@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-testcogoportutilsuncoded-connect@reversodev/oceanic-fleetwilscanner@khalitovadel/abstract-repository@oiti/documentoscopy-react-native@respondea/cordova-plugin-v-inappbrowser@mink-opn/build-tokensquoc-testreact-native-slider-kf@infinitebrahmanuniverse/nolb-pare@prodam/prodam-types@saaspe/componentsparcel-plugin-workbox3plginexpand-react-bridgeopea-bootstraapluminos-ui-coresklif-ui-kitsklif-apits-handy@everything-registry/sub-chunk-2409jawwy-sdkjawwy_gamification_releasevlodia.db@deepakorg/test@deepak757/testreact-native-sphereuisphereuijawwy_libraryeginnovations-capacitor-pluginreact-native-credit-card-pkgp149-table@rabailriaz/hisaab-web-portalsklif-uimachinebeemrcaps@mediakular/svelte-data-gridreact-native-jawwy_samplegriffin-ui-libraryjualwkakokowawkzl2kzl3kzl4kzl5mamaowhalowpoeawgrtaudahjilha1jilha2jilha3jilha4jilha5mawalwlmdramml8487lpommlowolpomomo1momo2momo3momo4
3.1.0

1 year ago

3.0.0

3 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

9 years ago