Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Relative path inside a project

  • path
  • dirname
  • join
project_dir/
   /bin/
       code.js
   /templates
       main.html
const path = require('path');

console.log(__filename);
console.log(__dirname);

const root = path.dirname(__dirname)
console.log(root);

const templates = path.join(root, 'templates');
console.log(templates);

const rel_path_to_file = path.join(root, 'templates', 'main.html');
console.log(rel_path_to_file);