Skip to main content

path

The node:path module provides utilities for working with file and directory paths. It can be accessed using:

import path from 'node:path';

Usage in Deno

import * as mod from "node:path";

Namespaces

N
v
default

The node:path module provides utilities for working with file and directory paths. It can be accessed using:

    N
    v
    path

    The node:path module provides utilities for working with file and directory paths. It can be accessed using:


      interface default.FormatInputPathObject

      Usage in Deno

      import mod from "node:path";
      

      Properties #

      #root: string | undefined
      optional

      The root of the path such as '/' or 'c:'

      #dir: string | undefined
      optional

      The full directory path such as '/home/user/dir' or 'c:\path\dir'

      #base: string | undefined
      optional

      The file name including extension (if any) such as 'index.html'

      #ext: string | undefined
      optional

      The file extension (if any) such as '.html'

      #name: string | undefined
      optional

      The file name without extension (if any) such as 'index'


      interface default.ParsedPath

      Usage in Deno

      import mod from "node:path";
      

      A parsed path object generated by path.parse() or consumed by path.format().

      Properties #

      #root: string

      The root of the path such as '/' or 'c:'

      #dir: string

      The full directory path such as '/home/user/dir' or 'c:\path\dir'

      #base: string

      The file name including extension (if any) such as 'index.html'

      #ext: string

      The file extension (if any) such as '.html'

      #name: string

      The file name without extension (if any) such as 'index'


      interface default.PlatformPath

      Usage in Deno

      import mod from "node:path";
      

      Properties #

      #sep: "\\" | "/"
      readonly

      The platform-specific file separator. '\' or '/'.

      #delimiter: ";" | ":"
      readonly

      The platform-specific file delimiter. ';' or ':'.

      Posix specific pathing. Same as parent object on posix.

      Windows specific pathing. Same as parent object on windows

      Methods #

      #normalize(path: string): string

      Normalize a string path, reducing '..' and '.' parts. When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.

      #join(...paths: string[]): string

      Join all arguments together and normalize the resulting path.

      #resolve(...paths: string[]): string

      The right-most parameter is considered {to}. Other parameters are considered an array of {from}.

      Starting from leftmost {from} parameter, resolves {to} to an absolute path.

      If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.

      #matchesGlob(
      path: string,
      pattern: string,
      ): boolean

      The path.matchesGlob() method determines if path matches the pattern.

      #isAbsolute(path: string): boolean

      Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.

      If the given {path} is a zero-length string, false will be returned.

      #relative(
      from: string,
      to: string,
      ): string

      Solve the relative path from {from} to {to} based on the current working directory. At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.

      #dirname(path: string): string

      Return the directory name of a path. Similar to the Unix dirname command.

      #basename(
      path: string,
      suffix?: string,
      ): string

      Return the last portion of a path. Similar to the Unix basename command. Often used to extract the file name from a fully qualified path.

      #extname(path: string): string

      Return the extension of the path, from the last '.' to end of string in the last portion of the path. If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string.

      #parse(path: string): ParsedPath

      Returns an object from a path string - the opposite of format().

      #format(pathObject: FormatInputPathObject): string

      Returns a path string from an object - the opposite of parse().

      #toNamespacedPath(path: string): string

      On Windows systems only, returns an equivalent namespace-prefixed path for the given path. If path is not a string, path will be returned without modifications. This method is meaningful only on Windows system. On POSIX systems, the method is non-operational and always returns path without modifications.


      interface path.FormatInputPathObject

      Usage in Deno

      import { path } from "node:path";
      

      Properties #

      #root: string | undefined
      optional

      The root of the path such as '/' or 'c:'

      #dir: string | undefined
      optional

      The full directory path such as '/home/user/dir' or 'c:\path\dir'

      #base: string | undefined
      optional

      The file name including extension (if any) such as 'index.html'

      #ext: string | undefined
      optional

      The file extension (if any) such as '.html'

      #name: string | undefined
      optional

      The file name without extension (if any) such as 'index'


      interface path.ParsedPath

      Usage in Deno

      import { path } from "node:path";
      

      A parsed path object generated by path.parse() or consumed by path.format().

      Properties #

      #root: string

      The root of the path such as '/' or 'c:'

      #dir: string

      The full directory path such as '/home/user/dir' or 'c:\path\dir'

      #base: string

      The file name including extension (if any) such as 'index.html'

      #ext: string

      The file extension (if any) such as '.html'

      #name: string

      The file name without extension (if any) such as 'index'


      interface path.PlatformPath

      Usage in Deno

      import { path } from "node:path";
      

      Properties #

      #sep: "\\" | "/"
      readonly

      The platform-specific file separator. '\' or '/'.

      #delimiter: ";" | ":"
      readonly

      The platform-specific file delimiter. ';' or ':'.

      Posix specific pathing. Same as parent object on posix.

      Windows specific pathing. Same as parent object on windows

      Methods #

      #normalize(path: string): string

      Normalize a string path, reducing '..' and '.' parts. When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.

      #join(...paths: string[]): string

      Join all arguments together and normalize the resulting path.

      #resolve(...paths: string[]): string

      The right-most parameter is considered {to}. Other parameters are considered an array of {from}.

      Starting from leftmost {from} parameter, resolves {to} to an absolute path.

      If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.

      #matchesGlob(
      path: string,
      pattern: string,
      ): boolean

      The path.matchesGlob() method determines if path matches the pattern.

      #isAbsolute(path: string): boolean

      Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.

      If the given {path} is a zero-length string, false will be returned.

      #relative(
      from: string,
      to: string,
      ): string

      Solve the relative path from {from} to {to} based on the current working directory. At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.

      #dirname(path: string): string

      Return the directory name of a path. Similar to the Unix dirname command.

      #basename(
      path: string,
      suffix?: string,
      ): string

      Return the last portion of a path. Similar to the Unix basename command. Often used to extract the file name from a fully qualified path.

      #extname(path: string): string

      Return the extension of the path, from the last '.' to end of string in the last portion of the path. If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string.

      #parse(path: string): ParsedPath

      Returns an object from a path string - the opposite of format().

      #format(pathObject: FormatInputPathObject): string

      Returns a path string from an object - the opposite of parse().

      #toNamespacedPath(path: string): string

      On Windows systems only, returns an equivalent namespace-prefixed path for the given path. If path is not a string, path will be returned without modifications. This method is meaningful only on Windows system. On POSIX systems, the method is non-operational and always returns path without modifications.


      namespace default

      Usage in Deno

      import mod from "node:path";
      

      The node:path module provides utilities for working with file and directory paths. It can be accessed using:

      import path from 'node:path';
      

      Interfaces #

      See #


      namespace path

      Usage in Deno

      import { path } from "node:path";
      

      The node:path module provides utilities for working with file and directory paths. It can be accessed using:

      import path from 'node:path';
      

      Interfaces #

      See #

      variable path


      Did you find what you needed?

      Privacy policy