Import Node built-in modules or locally installed third-part module:
// These modules are built in to Nodeconstfs=require("fs"); // The built-in filesystem moduleconsthttp=require("http"); // The built-in HTTP module// The Express HTTP server framework is a third-party module.// It is not part of Node but has been installed locally.constexpress=require("express");
// Import the entire stats object, with all of its functionsconststats=require('./stats.js');// We've got more functions than we need, but they're neatly// organized into a convenient "stats" namespace.let average =stats.mean(data);
Or import only a function:
// Alternatively, we can use idiomatic destructuring assignment to import// exactly the functions we want directly into the local namespace:const { stddev } =require('./stats.js');// This is nice and succinct, though we lose a bit of context// without the 'stats' prefix as a namespace for the stddev() function.\let sd =stddev(data);