Nodejs:path Object

Source: Internet
Author: User

Module Path:

Path.normalize (url)

Path.join (url1, Url2,..)

Path.resolve (url1, Url2,..)

Path.relative (url1, Url2)

Path.dirname (url)

Path.basename (url)

Path.extname (url)

TIPS:

The above is the path Object's api, the invocation is convenient and concise, generally in the project I will first write a top-level directory

var publicdir = path.resolve (__dirname, './src ')

The remaining subdirectories are derived from this top-level directory

var pagesdir  = path.resolve (publicdir, './pages ')var staticdir = Path.resolve ( publicdir, '. Static ')var buildDir  = path.resolve (publicdir, './build ')var Vendordir = path.resolve (publicdir, './vendor ')

finally, The object is mounted, other files need to be used to the path, the direct introduction of the

Module.exports = {    pagesdir:    './pages ')    staticdir:   '. static ')    BuildDir :    './build ')    vendordir:   './vendor ')}

API Example:
varPath = require (' path ');/** Format Path:. /return to the previous level, so the result is *--'/foo/bar/baz/asdf '*/Path.normalize ('/foo/bar//baz/asdf/quux/. ');/** Stitching Path: after stitching is completed call normalize (), results same as *---'/FOO/BAR/BAZ/ASDF '*/Path.join ('///foo ', ' bar ', '//baz/asdf ', ' Quux ', ' ... ');/** Path navigation: equals CD once per Sub-path*/Path.resolve (' Foo/bar ', '/tmp/file/', ' ... ', ' a '. /subfile ')/** Relative Path: b The path relative to a is: '. /.. /IMPL/BBB ', The result on a path can be accessed to the B file *--and '. /.. /IMPL/BBB '*/path.relative ('/DATA/ORANDEA/TEST/AAA ', '/data/orandea/impl/bbb ')/** Folder name: the name of the path where the folder is located *--'/foo/bar/baz/asdf '*/Path.dirname ('/foo/bar/baz/asdf/quux ')    /** File Path: returns the specified file name to exclude the suffix name *--' quux '*/Path.basename ('/foo/bar/baz/asdf/quux.html ', '. html ')/** Extension name: return file extension*/Path.extname (' Index.html ')//'. html 'Path.extname (' Index. ')//'. 'Path.extname (' Index ')//"'Module.exports={entry: [], output:{path:builddir, filename:' [name]/entry.js '    }};

Nodejs:path Object

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.