Answers for "require in js"

PHP
8

include and require in php

// Include a file, if it can't be found: continue.
<?php
include 'mainfile.php';
?>
  
// Alternatively: Require a file to be imported or quit if it can't be found
<?php
 require 'requiredfile.php';
?>
Posted by: Guest on April-25-2020
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
0

nodejs require

//What is require in Nodejs?
//Node.js follows the CommonJS module system, and the builtin require 
//function is the easiest way to include modules that exist in separate 
//files. The basic functionality of require is that it reads a JavaScript 
//file, executes the file, and then proceeds to return the exports object.
Posted by: Guest on May-11-2021

Browse Popular Code Answers by Language