Node.js

Table of Contents

Overview

Reference

_dirname

console.log(__dirname);
// Prints: /Users/mjr

console.log(path.dirname(__filename));
// Prints: /Users/mjr

path

const path = require('path');

resolve

The given sequence of paths is processed from right to left, with each subsequent path prepended until an absolute path is constructed.

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 the current working directory is /home/myself/node,
// this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'

Topics

exports vs. module.exports

How-to

Links