How to Use path. isAbsolute in node. js _ node. js-js tutorial

Source: Internet
Author: User
This article describes how to use the path. isAbsolute method in node. js. This article describes the method description, syntax, examples, and source code implementation of path. isAbsolute. For more information, see Method description:

Checks whether the path is an absolute path. An absolute path will be resolved to the same location, whether in the working directory or not.

Syntax:

The Code is as follows:


Path. isAbsolute (path)

Because this method belongs to the path module, You need to introduce the path module (var path = require ("path") before use "))

Receiving parameters:

Path

Example:

The Code is as follows:


// Posix examples:
Path. isAbsolute ('/foo/bar') // true
Path. isAbsolute ('/baz/..') // true
Path. isAbsolute ('qux/') // false
Path. isAbsolute ('.') // false
// Windows examples:
Path. isAbsolute ('// Server') // true
Path. isAbsolute ('C:/foo/.. ') // true
Path. isAbsolute ('bar \ Baz') // false
Path. isAbsolute ('.') // false

Source code:

The Code is as follows:


// Windows version
Exports. isAbsolute = function (path ){
Var result = splitDeviceRe.exe c (path ),
Device = result [1] | '',
IsUnc = device & device. charAt (1 )! = ':';
// UNC paths are always absolute
Return !! Result [2] | isUnc;
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.