ostrio:meteor-root

v1.2.2Published 2 days ago

support support

Meteor.rootPath

Get the path to currently running instance of Meteor application on a server.

Features:

  • 🤓 Compatibility with Windows, Linux, and MacOS environments;
  • 👨‍💻 Globally available Meteor.rootPath — absolute path to programs/server directory;
  • 👨‍💻 Globally available Meteor.absolutePath — application root (path before .meteor in rootPath).

meteor-root atmosphere library

Installation

meteor add ostrio:meteor-root

Usage

1import path from 'path';
2
3const pathToFile = path.join(Meteor.rootPath, 'directory', 'file.json');

Returns absolute path to programs/server directory of the running app, without trailing slash. Same as server process.cwd().

1import path from 'path';
2
3const pathToFile = path.join(Meteor.absolutePath, 'private', 'file.json');

Returns application root when .meteor is present in rootPath (dev, meteor test-packages). In typical production bundles, equals Meteor.rootPath. See docs/paths-and-environments.md.

[!NOTE] Paths reflect where Meteor is running, not necessarily your git checkout. Test runners use temporary build directories.

TypeScript

Types ship via meteor-root.d.ts (module augmentation on meteor/meteor). The package uses zodern:types and package-types.json at publish time.

In your app, add zodern:types, configure tsconfig.json paths for meteor/* (see Meteor core types docs), then run meteor lint.

Testing

From the package directory:

npm install
npm test

Runs runtime tests (mtest) and TypeScript declaration tests (tsd). mtest requires a Chromium/Chrome binary for Puppeteer.

npm run test:once     # runtime only
npm run test:types    # declarations only

# Custom port (runtime)
npm run test:once -- --port 8888

# With local MongoDB (runtime)
MONGO_URL="mongodb://127.0.0.1:27017/meteor-root-test" npm run test:once

Special thanks

  • Thanks to @Konard for testing and maintaining Windows support.

Support this project: