JavaScript Node.js Basics Building a Command Line Application Making a GET Request with https

Michael Williams
PRO
Michael Williams
Pro Student 8,057 Points

Can someone explain "require" in plain english?

Andrew talks about the require method but doesn't explain it. So I went to the MDN link in the teacher's notes, and that wasn't much more helpful. Can someone explain (in plain English) what he's doing here with the require method?

He starts talking about require around the 4:30 mark.

1 Answer

Dario Bahena
Dario Bahena
10,687 Points

require is a method that is part of the node.js framework. In other words, it is globally accessible. You probably won't find it in MDN because it is not part of JavaScript itself. In node, if you want to use a library (module) you can use the require method to load it and make it accessible.

hypothetical: lets say you have a library that prints "hello" called 'somelib'

const someVariable = require('somelib')

// someVariable now contains the library which can be used to access its contents.
someVariable.print() // will print "hello"
Michael Williams
Michael Williams
Pro Student 8,057 Points

That's precisely the answer I was looking for. Thanks!