We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

JavaScript OS.Constants

JavaScript module OS.Constants contains Operating System-specific constants. This module is largely a companion to js-ctypes.

Using OS.Constants

From the main thread

To initialize OS.Constants for use in the main thread, add the following snippet to your code:


From a chrome worker

No initialization is required. Module OS.Constants is always available for chrome workers.



Constants related to system configuration.

Name The name of the operating system (e.g. "Darwin").
DEBUG Set to true on debug build configurations, non-existent otherwise.


Paths of well-known files and directories.

libxul The path to the file containing libxul. Useful, for instance, to access the platform code from JavaScript in conjunction with js-ctypes.
profileDir The path to the current profile.
homeDir The path to the user's home directory.
desktopDir The path to the user's desktop directory (or, if it doesn't exist, the path to the user's home directory).
winAppDataDir The path to the user's roaming application data directory.
winLocalAppDataDir The path to the user's local application data directory.
winStartMenuProgsDir The path to the programs subdirectory in the user's start menu.
macUserLibDir The path to the user's Library directory.
macLocalApplicationsDir The path to the local Applications directory.


Constants for interacting with libc. Useful mostly for using js-ctypes to interact with the following platforms:

  • MacOS X;
  • Android;
  • Linux;
  • other variants of Unix.

OS.Constants.libc is available on all platforms, although some constants are not defined everywhere. Before using a constant, you should check that it is defined.

Error values

EACCES Permission denied
EAGAIN Resource temporarily unavailable
EBADF Bad file descriptor
EEXIST File exists
EFAULT Bad address
EFBIG File too large
EINVAL Invalid argument
EIO Input/output error
EISDIR Is a directory

(Not always available under Windows) Too many levels of symbolic links.

EMFILE Too many open files in the process
ENAMETOOLONG Name too long
ENFILE Too many open files on the system
ENOENT No such file or directory
ENOMEM Cannot allocate memory
ENOSPC No space on device
ENOTDIR Is not a directory
ENXIO Device no configured or does not support operation
EOPNOTSUPP (Not always available under Windows) Operation not supported.
EOVERFLOW (Not always available under Windows) Value too large to be stored in datatype.
EPERM Operation not permitted
ERANGE Result too large
ETIMEDOUT (Not always available under Windows) Operation timed out.
EWOULDBLOCK (Not always available under Windows) Operation would block.
EXDEV Cross-device link

Opening files

Unix access rights

Defined on all platforms but meaningful only on Unix.

S_IRWXU Current User can Read, Write, eXecute the file. Equivalent to S_IRUSR | S_IWUSR | S_IXUSR.
S_IRUSR Current User can Read the file.
S_IWUSR Current User can Write (modify) the file.
S_IXUSR Current User can eXecute the file.
S_IRWXG Current GRouP of the current user can Read, Write, eXecute the file. Equivalent to S_IRGRP | S_IWGRP | S_IXGRP.
S_IRGRP Current GRouP of the current user can Read the file.
S_IWGRP Current GRouP of the current user can Write (modify) the file.
S_IXGRP Current GRouP of the current user can eXecute the file.
S_IRWXO All Other users can Read, Write, eXecute the file. Equivalent to S_IROTH | S_IWOTH | S_IXOTH.
S_IROTH All Other users can Read the file.
S_IWOTH All Other users can Write (modify) the file.
S_IXOTH All Other users can eXecute the file.

Unix opening mode

O_APPEND Open the file for appending.
O_CREAT Create the file if it does not exist yet.
O_DIRECTORY (Linux only) Succeed only of the file is a directory.
O_EVTONLY Descriptor requested for event notifications only.
O_EXCL Raise an error if O_CREAT is set and the file exists.
O_EXLOCK Atomically obtain an exclusive lock.
O_NOFOLLOW Do not follow symbolic links.
O_NONBLOCK Do not block on open or for data to become available.
O_RDONLY Open the file for read only.
O_RDWR Open the file for read and write.
O_SHLOCK Atomically obtain a shared lock.
O_SYMLINK Allow opening of symbolic links.
O_SYNC (Linux only) Open for purely synchronous access.
O_TRUNC Truncate the file.
O_WRONLY Open the file for write only.


Constants for interacting with the Windows API. OS.Constants.Win is undefined on non-Windows platforms. Useful mostly in conjunction with js-ctypes.


Document Tags and Contributors

Contributors to this page: chrisdavidmills, evanxd, marco-c, j4nu5, rnewman, Yoric
Last updated by: evanxd,