Path Module

Node comes with a bunch of useful modules. You will find information about its modules on Node's online documentation. We will look at a few of these.

Let's play around with the Path module first.

// index.js file
const path = require("path");

const pathObj = path.parse(__filename);

console.log(pathObj);

Notice the argument to require is not a file path. It simply is the name of the module. This is the pattern we use to load Node's built-in modules.

Run index.js and you will get an output similar to this one:

{
  root: '/',
  dir: '/Users/alimadooei/Desktop/CS280/01-FA-20/staging/code/app',
  base: 'index.js',
  ext: '.js',
  name: 'index'
}