Path. Resolve method in node.js
- 2020-03-30 04:34:08
- OfStack
Method description:
Parses the character of the argument to position into an absolute path.
Grammar:
path.resolve([from ...], to)
Since this method belongs to the path module, you need to introduce the path module (var path= require(" path ")) before using it.
Receiving parameters:
From The source path
To The string that will be parsed to the absolute path
Example:
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 sequential CD command shell.
path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')
Similar to:
cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd