const path = require('path'); const webDirectory = 'public'; const imageDirectory = 'images'; const imagePath = path.join(webDirectory, imageDirectory); // Result: 'public/images'
const path = require('path'); const mainDirectory = 'src'; const moduleName = 'app'; const fileExtension = '.js'; const filePath = path.join(mainDirectory, moduleName + fileExtension); // Result: 'src/app.js'This example shows how to construct a file path using the `path.join()` method. It combines a main directory called "src" with a module name called "app" and a file extension of ".js". The result is a new path that contains the full file path, including the directory, module name, and file extension. Package Library: Node.js - Path Module