• Node.js Video Tutorials

Node.js - path.delimiter Property



The Node.js path.delimiter property of path module shows a disparity based on the platform where it got executed. In case of Windows operating systems, it will return a semi-colon (;) and in POSIX systems it will return colon (:).

Syntax

Following is the example of the Node.js path.delimiter property −

path.delimeter

Parameters

This method does not accept any parameters.

Return value

The return value in node.js delimiter is the character or string that separates one element of a list from another. It can be used to split strings into substrings, separate words within a sentence, and even determine how data should be displayed when it is print. The possible for returned string are ';' on Windows operating systems and ':' on POSIX operating systems.

Example

In the following example, we are trying to get the platform-specific delimiter by using the Node.js path.delimiter property of OS module.

const path = require('path');
console.log(path.delimiter);

Output

If we execute the code in online compiler, it will display the results according to POSIX operating system.

Following is the output of the above program −

:

Note − If we execute the above code on Windows operating system, output will not be similar to POSIX.

When we execute the above program in WINDOWS operating system, the path.delimiter property will return semi-colon ';'.

;

Example

In the example below, we are trying to print the platform-specific delimiter in another way by using process.env.PATH property.

const path = require('path');
const process = require('process');

var delimiter = path.delimiter;
console.log(process.env.PATH);

Output

Following is the output of the above program in online compiler (POSIX) −

/usr/local/bin/factor:/root/.sdkman/candidates/kotlin/current/bin:/usr/GNUstep/System/Tools:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/scriba/bin:/usr/local/smlnj/bin:/usr/local/bin/std:/usr/local/bin/extra:/usr/local/fantom/bin:/usr/local/dart/bin:/usr/libexec/sdcc:/usr/local/icon-v950/bin:/usr/local/mozart/bin:/opt/Pawn/bin:/opt/pash/Source/PashConsole/bin/Debug/:.:/root/.sdkman/candidates/kotlin/current/bin:/usr/bin:/sbin:/bin

If we compile and run the above program on WINDOWS operating system, the process.env.PATH property will print the platform specific delimiter.

C:\Python310\Scripts\;C:\Python310\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Users\Lenovo\AppData\Local\Microsoft\WindowsApps;C:\Users\Lenovo\AppData\Roaming\npm;C:\Users\Lenovo\AppData\Local\Programs\Microsoft VS Code\bin;

Example

Following example is another way to get the platform-specific delimiter.

const path = require('path');
const process = require('process');

var delimiter = path.delimiter;
console.log(process.env.PATH.split(path.delimiter));

Output

Following is the output of the above program in online compiler (POSIX) −

[ '/usr/local/bin/factor',
  '/root/.sdkman/candidates/kotlin/current/bin',
  '/usr/GNUstep/System/Tools',
  '/usr/local/bin',
  '/usr/bin',
  '/usr/local/sbin',
  '/usr/sbin','/usr/local/scriba/bin',
  '/usr/local/smlnj/bin',
  '/usr/local/bin/std',
  '/usr/local/bin/extra',
  '/usr/local/fantom/bin',
  '/usr/local/dart/bin',
  '/usr/libexec/sdcc',
  '/usr/local/icon-v950/bin',
  '/usr/local/mozart/bin',
  '/opt/Pawn/bin',
  '/opt/pash/Source/PashConsole/bin/Debug/',
  '.',
  '/root/.sdkman/candidates/kotlin/current/bin',
  '/usr/bin',
  '/sbin',
  '/bin' ]

If we compile and run the above program on WINDOWS operating system, the process.env.PATH.split() method will print the platform specific delimiter in an array by splitting each path.

[
  'C:\\Python310\\Scripts\\',
  'C:\\Python310\\',
  'C:\\WINDOWS\\system32',
  'C:\\WINDOWS',
  'C:\\WINDOWS\\System32\\Wbem',
  'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\',
  'C:\\WINDOWS\\System32\\OpenSSH\\',
  'C:\\ProgramData\\chocolatey\\bin',
  'C:\\Program Files\\nodejs\\',
  'C:\\Users\\Lenovo\\AppData\\Local\\Microsoft\\WindowsApps',
  'C:\\Users\\Lenovo\\AppData\\Roaming\\npm',
  'C:\\Users\\Lenovo\\AppData\\Local\\Programs\\Microsoft VS Code\\bin',
  ''
]
nodejs_path_module.htm
Advertisements