Intro
What is Bun?
Installation
Quickstart
TypeScript
Templating
bun init
bun create
Runtime
bun run
File types
TypeScript
JSX
Environment variables
Bun APIs
Web APIs
Node.js compatibility
Single-file executable
Plugins
Watch mode
Module resolution
Auto-install
bunfig.toml
Debugger
Framework APISOON
Package manager
bun install
bun add
bun remove
bun update
bun publish
bun outdated
bun link
bun pm
Global cache
Workspaces
Lifecycle scripts
Filter
Lockfile
Scopes and registries
Overrides and resolutions
Patch dependencies
.npmrc support
Bundler
Bun.build
HTML & static sites
CSS
Fullstack Dev Server
Hot reloading
Loaders
Plugins
Macros
vs esbuild
Test runner
bun test
Writing tests
Watch mode
Lifecycle hooks
Mocks
Snapshots
Dates and times
DOM testing
Code coverage
Package runner
bunx
API
HTTP server
HTTP client
WebSockets
Workers
Binary data
Streams
SQL
S3 Object Storage
File I/O
import.meta
SQLite
FileSystemRouter
TCP sockets
UDP sockets
Globals
$ Shell
Child processes
HTMLRewriter
Hashing
Console
Cookie
FFI
C Compiler
Testing
Utils
Node-API
Glob
DNS
Semver
Color
Transpiler
Project
Roadmap
Benchmarking
Contributing
Building Windows
Bindgen
License
Search the docs...
/
Intro
What is Bun?
Installation
Quickstart
TypeScript
Templating
bun init
bun create
Runtime
bun run
File types
TypeScript
JSX
Environment variables
Bun APIs
Web APIs
Node.js compatibility
Single-file executable
Plugins
Watch mode
Module resolution
Auto-install
bunfig.toml
Debugger
Framework APISOON
Package manager
bun install
bun add
bun remove
bun update
bun publish
bun outdated
bun link
bun pm
Global cache
Workspaces
Lifecycle scripts
Filter
Lockfile
Scopes and registries
Overrides and resolutions
Patch dependencies
.npmrc support
Bundler
Bun.build
HTML & static sites
CSS
Fullstack Dev Server
Hot reloading
Loaders
Plugins
Macros
vs esbuild
Test runner
bun test
Writing tests
Watch mode
Lifecycle hooks
Mocks
Snapshots
Dates and times
DOM testing
Code coverage
Package runner
bunx
API
HTTP server
HTTP client
WebSockets
Workers
Binary data
Streams
SQL
S3 Object Storage
File I/O
import.meta
SQLite
FileSystemRouter
TCP sockets
UDP sockets
Globals
$ Shell
Child processes
HTMLRewriter
Hashing
Console
Cookie
FFI
C Compiler
Testing
Utils
Node-API
Glob
DNS
Semver
Color
Transpiler
Project
Roadmap
Benchmarking
Contributing
Building Windows
Bindgen
License
Theimport.meta
object is a way for a module to access information about itself. It's part of the JavaScript language, but its contents are not standardized. Each "host" (browser, runtime, etc) is free to implement any properties it wishes on theimport.meta
object.
Bun implements the following properties.
import.meta.dir;// => "/path/to/project"import.meta.file;// => "file.ts"import.meta.path;// => "/path/to/project/file.ts"import.meta.url;// => "file:///path/to/project/file.ts"import.meta.main;// `true` if this file is directly executed by `bun run`// `false` otherwiseimport.meta.resolve("zod");// => "file:///path/to/project/node_modules/zod/index.js"
import.meta.dir | Absolute path to the directory containing the current file, e.g./path/to/project . Equivalent to__dirname in CommonJS modules (and Node.js) |
import.meta.dirname | An alias toimport.meta.dir , for Node.js compatibility |
import.meta.env | An alias toprocess.env . |
import.meta.file | The name of the current file, e.g.index.tsx |
import.meta.path | Absolute path to the current file, e.g./path/to/project/index.ts . Equivalent to__filename in CommonJS modules (and Node.js) |
import.meta.filename | An alias toimport.meta.path , for Node.js compatibility |
import.meta.main | Indicates whether the current file is the entrypoint to the currentbun process. Is the file being directly executed bybun run or is it being imported? |
| Resolve a module specifier (e.g.
|
import.meta.url | Astring url to the current file, e.g.file:///path/to/project/index.ts . Equivalent toimport.meta.url in browsers |