Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/node-core-library > PackageJsonLookup > tryGetPackageFolderFor

PackageJsonLookup.tryGetPackageFolderFor() method

Returns the absolute path of a folder containing a package.json file, by looking upwards from the specified fileOrFolderPath. If no package.json can be found, undefined is returned.


tryGetPackageFolderFor(fileOrFolderPath: string): string | undefined;


fileOrFolderPathstringa relative or absolute path to a source file or folder that may be part of a package


string | undefined

an absolute path to a folder containing a package.json file


The fileOrFolderPath is not required to actually exist on disk. The fileOrFolderPath itself can be the return value, if it is a folder containing a package.json file. Both positive and negative lookup results are cached.