Require

suggest change

Versions

require is the CommonJS loader. It has been in Node from the start. The call shape below has not changed.

Introduction

require() loads a file or an installed package. Node resolves a relative path from the file that calls require, not from the shell's current directory. A bare name such as require('express') is looked up in node_modules.

Syntax

Remarks

module.exports is what the caller receives. If you never assign it, require still runs the file and returns an empty object, so the file can be loaded for side effects. Nothing is exported under the name .export. That is not a Node API.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents