Install and Require HelmetJS

2 posts Sun, Feb 5, 2023 at 08:55 PM edited Feb 5, 2023 at 09:08 PM in Topcoder Academy

The Require Function

The require function in JavaScript is used in the server-side programming environment, specifically in Node.js. It's used to include a module (i.e., a file containing code) in the current file and make its functions and variables available for use. The require function returns the exports (i.e., public interface) of the included module.


const module = require('module');


Suppose we have a module named math.js with the following code:

exports.add = function(a, b) {
  return a + b;

We can include this module in another file and use the add function like this:

const math = require('./math');
console.log(math.add(1, 2));
View: Threaded  |  Flat
Sign In or Register to comment.