Docs
Language Manual
  • Introduction
  • Cheatsheet
JavaScript
  • BuckleScript
  • ReasonReact
  • GenType
API
Overview
JavaScript
  • Belt Stdlib
  • Js Module
PlaygroundBlogCommunity
  • Playground
  • Blog
  • Community
  • Twitter
  • Discord
  • Github
BuckleScriptv7
Overview
  • Introduction
  • Installation
  • New Project
  • Try
  • Concepts Overview
  • Upgrade Guide to v7
Interop
  • Overview
  • Cheatsheet
  • Embed Raw JavaScript
  • Common Data Types
  • Intro to External
  • Bind to Global Values
  • Null, Undefined & Option
  • Object
  • Object 2
  • Class
  • Function
  • Property access
  • Return Value Wrapping
  • Import & Export
  • Regular Expression
  • Exceptions
  • JSON
  • Pipe First
  • Generate Converters & Helpers
  • Better Data Structures Printing (Debug Mode)
  • NodeJS Special Variables
  • Handling JS Naming Collisions
  • Miscellaneous
  • Browser Support & Polyfills
  • Decorators
Build System
  • Overview
  • Configuration
  • Automatic Interface Generation
  • Interop with Other Build System
  • Performance
  • Advanced
Standard Library
  • Overview
Advanced
  • Conditional Compilation
  • Extended Compiler Options
  • Use Existing OCaml Libraries
  • Difference from Native OCaml
  • Compiler Architecture & Principles
  • Comparison to Js_of_ocaml
Docs / BuckleScript / NodejsSpecialVariables

NodeJS Special Variables

NodeJS has several file local variables: __dirname, __filename, _module, and require. Their semantics are more like macros instead of functions.

bs.node exposes support for these.

RE
let dirname: option(string) = [%bs.node __dirname]; let filename: option(string) = [%bs.node __filename]; let _module: option(Node.node_module) = [%bs.node _module]; let require: option(Node.node_require) = [%bs.node require];