Mô-đun đường dẫn Node.js

❮ Mô-đun tích hợp


Thí dụ

Trích xuất tên tệp từ đường dẫn tệp:

var path = require('path');
var filename = path.basename('/Users/Refsnes/demo_path.js');
console.log(filename);

Định nghĩa và Cách sử dụng

Mô-đun Đường dẫn cung cấp cách làm việc với các thư mục và đường dẫn tệp.


Cú pháp

Cú pháp để bao gồm mô-đun Đường dẫn trong ứng dụng của bạn:

var path = require('path');

Thuộc tính và phương thức đường dẫn

Method Description
basename() Returns the last part of a path
delimiter Returns the delimiter specified for the platform
dirname() Returns the directories of a path
extname() Returns the file extension of a path
format() Formats a path object into a path string
isAbsolute() Returns true if a path is an absolute path, otherwise false
join() Joins the specified paths into one
normalize() Normalizes the specified path
parse() Formats a path string into a path object
posix Returns an object containing POSIX specific properties and methods
relative() Returns the relative path from one specified path to another specified path
resolve() Resolves the specified paths into an absolute path
sep Returns the segment separator specified for the platform
win32 Returns an object containing Windows specific properties and methods

❮ Mô-đun tích hợp