Open In App

Node.js os.constants

Last Updated : 02 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The os.constants is an inbuilt application programming interface of the os module which is used to get operating system specified constants for error code, signal constants, priority constants, dlopen constants, etc.

Syntax:  

os.constants

Return Value: It returns an object that contains operating system-specified constants. 

Examples: error codes, signal constants, priority constants, dlopen constants, etc.

Signal constants can be accessed by using os.constants.signals and priority constants can be accessed by using os.constants.priority. 

Some of the constants are listed below:

Signal Constants: 

Constant Description
SIGHUP It is sent to specify when a parent process exits or a controlling terminal is closed.
SIGINT It is sent to specify when a user interrupts a process. (like (Ctrl+C)).
SIGQUIT It is sent to specify that a user wishes to terminate the process & perform a core dump.
SIGILL It is sent to a process to notify that it has attempted to perform a malformed, unknown, illegal, or privileged instruction.
SIGTRAP It is sent to a process on exception occurred.
SIGABRT It is sent to a process to request abort.
SIGIOT It is the synonym for SIGABRT.
SIGBUS It is sent to a process to notify for a bus error.
SIGFPE It is sent to a process to notify for an illegal arithmetic operation.
SIGKILL It is sent to a process to terminate immediately.
SIGUSR1 SIGUSR2 It is sent to a process to recognize user-defined conditions.
SIGSEGV It is sent to a process to notify for a segmentation fault.
SIGPIPE It is sent to a process when it has tried to write to a disconnected pipe.
SIGALRM It is sent to a process for a system timer elapses.
SIGTERM It is sent to a process to request termination.
SIGCHLD It is sent to a process after a child process terminates.
SIGSTKFLT It is sent to a process to specify a stack fault on a coprocessor.
SIGCONT It is sent to tell the OS to continue a paused process.
SIGSTOP It is sent to direct the OS to halt a process.
SIGTSTP It is sent to a process to request it to stop.
SIGBREAK It is sent to specify that a user wishes to interrupt a process.
SIGTTIN It is sent when a process reads from the TTY while in the background.
SIGTTOU It is sent when a process writes to the TTY while in the background.
SIGURG It is sent to a process to indicate that a socket has urgent data to read.
SIGXCPU It is sent when a process has exceeded its CPU usage limit.
SIGXFSZ It is sent when a process grows a file larger than the maximum allowed.
SIGVTALRM It is sent to a process for an elapsed virtual timer occurrence.
SIGPROF It is sent to a process after a system timer has elapsed.
SIGWINCH It is sent to a process after a controlling terminal changed its size.
SIGIO It is sent to a process to signify that I/O is available.
SIGPOLL It is the synonym for SIGIO.
SIGLOST It is sent to a process to indicate that a file lock has been lost.
SIGPWR It is sent to a process to notify of a power failure.
SIGINFO It is the synonym for SIGPWR.
SIGSYS It is sent to a process to notify for bad argument.
SIGUNUSED It is the synonym for SIGSYS.

Error constants: 

1. POSIX error constant 
 

Constant Description
E2BIG It is to specify a long list of arguments than expected.
EACCES It is to specify insufficient permissions for the operation.
EADDRINUSE It is to specify an already used network address.
EADDRNOTAVAIL It is to specify the network address currently unavailable.
EAFNOSUPPORT It is to specify the unsupported network address family.
EAGAIN It is to specify that there is no data available and to try the operation again later.
EALREADY It is to specify that the socket has a pending connection in progress.
EBADF It is to specify an invalid file descriptor.
EBADMSG It is to specify an invalid data message.
EBUSY It is to specify that a device or resource is busy.
ECANCELED It is to specify that an operation was canceled.
ECHILD It is to specify not to have any child processes.
ECONNABORTED It is to specify the aborted network connection.
ECONNREFUSED It is to specify the refused network connection.
ECONNRESET It is to specify the reset network connection.
EDEADLK It is to specify an avoided resource deadlock.
EDESTADDRREQ It is to specify that a destination address is required.
EDOM It is to specify that an argument is out of the domain of the function.
EDQUOT It is to specify that the disk quota has been exceeded.
EEXIST It is to specify that the file already exists.
EFAULT It is to specify an invalid pointer address.
EFBIG It is to specify that the file is too large.
EHOSTUNREACH It is to specify that the host is unreachable.
EIDRM It is to specify that the identifier has been removed.
EILSEQ It is to specify an illegal byte sequence.
EINPROGRESS It is to specify that an operation is already in progress.
EINTR It is to specify that a function call was interrupted.
EINVAL It is to specify that an invalid argument was provided.
EIO It is to specify an otherwise unspecified I/O error.
EISCONN It is to specify that the socket is connected.
EISDIR It is to specify that the path is a directory.
ELOOP It is to specify too many levels of symbolic links in a path.
EMFILE It is to specify that there are too many open files.
EMLINK It is to specify that there are too many hard links to a file.
EMSGSIZE It is to specify that the provided message is too long.
EMULTIHOP It is to specify that a multihop was attempted.
ENAMETOOLONG It is to specify that the filename is too long.
ENETDOWN It is to specify that the network is down.
ENETRESET It is to specify that the connection has been aborted by the network.
ENETUNREACH It is to specify that the network is unreachable.
ENFILE It is to specify too many open files in the system.
ENOBUFS It is to specify that no buffer space is available.
ENODATA It is to specify that no message is available on the stream head read queue.
ENODEV It is to specify that there is no such device.
ENOENT It is to specify that there is no such file or directory.
ENOEXEC It is to specify an exec format error.
ENOLCK It is to specify that there are no locks available.
ENOLINK It is to specify that a link has been severed.
ENOMEM It is to specify that there is not enough space.
ENOMSG It is to specify that there is no message of the desired type.
ENOPROTOOPT It is to specify that a given protocol is not available.
ENOSPC It is to specify that there is no space available on the device.
ENOSR It is to specify that there are no stream resources available.
ENOSTR It is to specify that a given resource is not a stream.
ENOSYS It is to specify that a function has not been implemented.
ENOTCONN It is to specify that the socket is not connected.
ENOTDIR It is to specify that the path is not a directory.
ENOTEMPTY It is to specify that the directory is not empty.
ENOTSOCK It is to specify that the given item is not a socket.
ENOTSUP It is to specify that a given operation is not supported.
ENOTTY It is to specify an inappropriate I/O control operation.
ENXIO It is to specify no such device or address.
EOPNOTSUPP It is to specify that an operation is not supported on the socket. Although ENOTSUP and EOPNOTSUPP have the same value on Linux, according to POSIX.1 these error values should be distinct)
EOVERFLOW It is to specify that a value is too large to be stored in a given data type.
EPERM It is to specify that the operation is not permitted.
EPIPE It is to specify a broken pipe.
EPROTO It is to specify a protocol error.
EPROTONOSUPPORT It is to specify an unsupported protocol.
EPROTOTYPE It is to specify the wrong type of protocol for a socket.
ERANGE It is to specify that the results are too large.
EROFS It is to specify that the file system is read-only.
ESPIPE It is to specify an invalid seek operation.
ESRCH It is to specify that there is no such process.
ESTALE It is to specify that the filehandle is stale.
ETIME It is to specify an expired timer.
ETIMEDOUT It is to specify that the connection timed out.
ETXTBSY It is to specify that a text file is busy.
EWOULDBLOCK It is to specify that the operation would block.
EXDEV It is to specify an improper link.

2. Windows specific error 
 

Constant Codes Constant Description
WSAEINTR It is to specify an interrupted function call.
WSAEBADF It is to specify an invalid filehandle.
WSAEACCES It is to specify insufficient permissions to complete the operation.
WSAEFAULT It is to specify an invalid pointer address.
WSAEINVAL It is to specify that an invalid argument was passed.
WSAEMFILE It is to specify that there are too many open files.
WSAEWOULDBLOCK It is to specify that a resource is temporarily unavailable.
WSAEINPROGRESS It is to specify that an operation is currently in progress.
WSAEALREADY It is to specify that an operation is already in progress.
WSAENOTSOCK It is to specify that the resource is not a socket.
WSAEDESTADDRREQ It is to specify that a destination address is required.
WSAEMSGSIZE It is to specify that the message size is too long.
WSAEPROTOTYPE It is to specify the wrong protocol type for the socket.
WSAENOPROTOOPT It is to specify a bad protocol option.
WSAEPROTONOSUPPORT It is to specify that the protocol is not supported.
WSAESOCKTNOSUPPORT It is to specify that the socket type is not supported.
WSAEOPNOTSUPP It is to specify that the operation is not supported.
WSAEPFNOSUPPORT It is to specify that the protocol family is not supported.
WSAEAFNOSUPPORT It is to specify that the address family is not supported.
WSAEADDRINUSE It is to specify that the network address is already in use.
WSAEADDRNOTAVAIL It is to specify that the network address is not available.
WSAENETDOWN It is to specify that the network is down.
WSAENETUNREACH It is to specify that the network is unreachable.
WSAENETRESET It is to specify that the network connection has been reset.
WSAECONNABORTED It is to specify that the connection has been aborted.
WSAECONNRESET It is to specify that the connection has been reset by the peer.
WSAENOBUFS It is to specify that there is no buffer space available.
WSAEISCONN It is to specify that the socket is already connected.
WSAENOTCONN It is to specify that the socket is not connected.
WSAESHUTDOWN It is to specify that data cannot be sent after the socket has been shutdown.
WSAETOOMANYREFS It is to specify that there are too many references.
WSAETIMEDOUT It is to specify that the connection has timed out.
WSAECONNREFUSED It is to specify that the connection has been refused.
WSAELOOP It is to specify that a name cannot be translated.
WSAENAMETOOLONG It is to specify that a name was too long.
WSAEHOSTDOWN It is to specify that a network host is down.
WSAEHOSTUNREACH It is to specify that there is no route to a network host.
WSAENOTEMPTY It is to specify that the directory is not empty.
WSAEPROCLIM It is to specify that there are too many processes.
WSAEUSERS It is to specify that the user quota has been exceeded.
WSAEDQUOT It is to specify that the disk quota has been exceeded.
WSAESTALE It is to specify a stale file handle reference.
WSAEREMOTE It is to specify that the item is remote.
WSASYSNOTREADY It is to specify that the network subsystem is not ready.
WSAVERNOTSUPPORTED It is to specify that the winsock.dll version is out of range.
WSANOTINITIALISED It is to specify that successful WSAStartup has not yet been performed.
WSAEDISCON It is to specify that graceful shutdown is in progress.
WSAENOMORE It is to specify that there are no more results.
WSAECANCELLED It is to specify that an operation has been canceled.
WSAEINVALIDPROCTABLE It is to specify that the procedure call table is invalid.
WSAEINVALIDPROVIDER It is to specify an invalid service provider.
WSAEPROVIDERFAILEDINIT It is to specify that the service provider failed to initialize.
WSASYSCALLFAILURE It is to specify a system call failure.
WSASERVICE_NOT_FOUND It is to specify that a service was not found.
WSATYPE_NOT_FOUND It is to specify that a class type was not found.
WSA_E_NO_MORE It is to specify that there are no more results.
WSA_E_CANCELLED It is to specify that the call was canceled.
WSAEREFUSED It is to specify that a database query was refused.

dlopen Constants: 
 

Constant Code Constant Description
RTLD_LAZY It performs lazy binding. Node.js sets this flag by default.
RTLD_NOW It solve all undefined symbols in the library before dlopen(3) returns.
RTLD_GLOBAL These symbols defined by the library will be made available for symbol resolution of subsequently loaded libraries.
RTLD_LOCAL The converse of RTLD_GLOBAL. This is the default behavior if neither flag is specified.
RTLD_DEEPBIND this make a self-contained library use its own symbols in preference to symbols from previously loaded libraries.

Priority constants: 
 

Constant Codes Constant Description
PRIORITY_LOW The minimum process scheduling priority.
PRIORITY_BELOW_NORMAL The process scheduling priority is below PRIORITY_NORMAL and above PRIORITY_LOW.
PRIORITY_NORMAL The process scheduling priority is normal or default.
PRIORITY_ABOVE_NORMAL The process scheduling priority is below PRIORITY_HIGH and above PRIORITY_NORMAL.
PRIORITY_HIGH The process scheduling priority below PRIORITY_HIGHEST and above PRIORITY_ABOVE_NORMAL.
PRIORITY_HIGHEST Process scheduling priority is maximum.

libuv Constants: 
 

Constant Codes Constant Description
UV_UDP_REUSEADDR  

The below examples illustrate the use of os.constants in Node.js:

Example 1: 

javascript




// Import os module
const os = require('os');
 
constants = os.constants;
 
// Printing all os.constants
console.log(constants);


Output: 

[Object: null prototype] {
  UV_UDP_REUSEADDR: 4,
  dlopen: [Object: null prototype] {},
  errno:
   [Object: null prototype] {
     E2BIG: 7,
     EACCES: 13,
     EADDRINUSE: 100,
     . . .
     PRIORITY_HIGH: -14,
     PRIORITY_HIGHEST: -20 } }

Example 2: 

javascript




// Import os module
const os = require('os');
 
constants = os.constants;
 
// Printing os.constants
 
// Signals constants
if(constants.signals != undefined){
    console.log("Signals:");
    console.log(constants.signals);
}
 
// Priority constants
if(constants.priority!=undefined){
    console.log("priority:");
    console.log(constants.priority);
}


Output: 

Signals:
[Object: null prototype] {
  SIGHUP: 1,
  SIGINT: 2,
  . . .
  PRIORITY_HIGH: -14,
  PRIORITY_HIGHEST: -20 }

Note: The above program will compile and run by using the node index.js command.

Reference: https://nodejs.org/api/os.html#os_os_constants



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads