I usually find this as the first line in node.js scripts/modules as well as phantomJS, casperJS etc. I\'m curious, if this is a common pattern for server-side javascript (SS
The others gave nice technical answers, but I wanted to provide a super simplified answer just in case it helps someone in the future. "require" isn't in itself a library, but it's used when you want access modules (libraries and frameworks and such). So it's not like "require" is the most popular library or anything like that :).
By the way, plenty of older code demands that you still use "require" (notice I avoided saying it's required), but new syntax has been developed (I guess with ES6, from 2015) using the word "import." I definitely prefer import, and it is used for the exact same purpose, though it does look a bit different.
Anyways, as the others mentioned, "require" means you are requiring (i.e. accessing) a module. But that doesn't necessarily mean that you are getting access to a library or framework... you might actually be getting access to another page that you yourself created! For example, you might see this:
- var Comment = require("./models/comment");
This just means "give me access to that comment file I made inside the models directory." This is also considered a module.
So you can think of it like this... you require some code (or you import it)... so that you can utilize it the way you want. If you didn't require/import it, you wouldn't get it.