Answers for "require path in node js"

1

what is require('path')

The path module provides utilities for working with file and directory paths.
It can be accessed using:
const path = require('path');

on POSIX;
path.basename('C:\temp\myfile.html');
// Returns: 'C:\temp\myfile.html'


On Windows:
path.basename('C:\temp\myfile.html');
// Returns: 'myfile.html'
Posted by: Guest on April-18-2021
7

Node require module

// Use require.main.require to get a module from the root folder.
const Globals = require.main.require("./globals.js");
const YourCustomModule = require("./yourmodule.js");

console.log(YourCustomModule.message);

// --- yourmodule.js ---
module.exports = {
	message: "Hello World!",
	otherData: "Hello Grepper!"
};
Posted by: Guest on May-25-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language