Nodejs filesystem: Difference between revisions
From wikinotes
(Created page with " = Paths = <blockquote> <syntaxhighlight lang="javascript"> const path = require('path'); const rcfile = path.resolve('foo.txt') // relative to abspath path.dirname(rcfile)...") |
(→Paths) |
||
Line 5: | Line 5: | ||
const path = require('path'); | const path = require('path'); | ||
const | const filepath = path.resolve('foo.txt') // relative to abspath | ||
path.dirname( | path.dirname(filepath) // '/home/you' | ||
path.basename( | path.basename(filepath) // 'foo.txt' | ||
path.extname( | path.extname(filepath) // '.txt' | ||
// nodejs does not expand ~ | // nodejs does not expand ~ |
Revision as of 17:21, 30 July 2021
Paths
const path = require('path'); const filepath = path.resolve('foo.txt') // relative to abspath path.dirname(filepath) // '/home/you' path.basename(filepath) // 'foo.txt' path.extname(filepath) // '.txt' // nodejs does not expand ~ // so replace it with the envvar '~/.zshrc'.replace('~', process.env.HOME)