Home  >  Article  >  Web Front-end  >  Instructions for using the path.resolve method in node.js_node.js

Instructions for using the path.resolve method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:28:231854browse

Method description:

Parse the characters at the to parameter into an absolute path.

Grammar:

Copy code The code is as follows:

path.resolve([from ...], to)

Since this method belongs to the path module, the path module needs to be introduced before use (var path= require(“path”) )

Receive parameters:

from source path
to A string that will be parsed to an absolute path

Example:

Copy code The code is as follows:

path.resolve('/foo/bar', './baz')

// returns

'/foo/bar/baz'

path.resolve('/foo/bar', '/tmp/file/')

// returns

'/tmp/file'

path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')

// if currently in /home/myself/node, it returns

'/home/myself/node/wwwroot/static_files/gif/image.gif'

Another way is to use it as a sequence of cd command shells.

Copy code The code is as follows:

path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')

is similar to:

Copy code The code is as follows:

cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn