Node.js Require()

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


This documentation focuses on explaining the uses and of the require() statement that NodeJS includes in their language.

Require is an import of certain files or packages used with NodeJS's modules. It is used to improve code structure and uses. require() is used on files that are installed locally, with a direct route from the file that is require'ing.


  • module.exports = {testFunction: testFunction};
  • var test_file = require('./testFile.js'); //Let us have a file named testFile
  • test_file.testFunction(our_data); //Let testFile have function testFunction


Using require() allows code to be structured in a way similar to Java's use of classes and public methods. If a function is .export'ed, it can be require'ed in another file to be used. If a file is not .export'ed, it cannot be used in another file.

Got any Node.js Question?