nodejs dirname 1

nodejs dirname

// Source Code: lib/path.js
// Description: The path module provides utilities for working with file and 
//              directory paths. It can be accessed using:

const path = require('path')
path.dirname('/foo/asdf/quux') 
// Returns:  '/foo/asdf'
/*	 dirname(Value ) Returns: 
  The path.dirname() method returns the directory name of a path, 
  similar to the Unix dirname command. Trailing directory separators 
  are ignored, see path.sep. A TypeError is thrown if path is not a string.   */

Here is what the above code is Doing:
1. We’re requiring the path module.
2. We’re calling the dirname() method on the path module.
3. We’re passing the string ‘/foo/asdf/quux’ as an argument to the dirname() method.
4. The dirname() method returns the directory name of a path, similar to the Unix dirname command.
5. The dirname() method returns the string ‘/foo/asdf’.

Similar Posts