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.


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


path.resolve('/foo/bar', './baz')
// returns
path.resolve('/foo/bar', '/tmp/file/')
// returns
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if currently in /home/myself/node, it returns

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

Related articles: