Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 16, 2023 16:48
Show Gist options
  • Save suhailgupta03/c68cdbd5e840b15ce6e29001ea88c77d to your computer and use it in GitHub Desktop.
Save suhailgupta03/c68cdbd5e840b15ce6e29001ea88c77d to your computer and use it in GitHub Desktop.
// FILE - 1
function greet() {
console.log('Hello');
}
module.exports = greet;
// this is the way to export a function
// from a module
// module means file
var myGreetFunction = require('./test.js');
// this basically means loading a file
// and assigning the exported variables
// to a variable in this file
// in this case, the exported variable is a
// function
console.log(myGreetFunction);
@suhailgupta03
Copy link
Author

node test2.js

@suhailgupta03
Copy link
Author

EDIT: Change require('./test.js'); to require('./test1.js');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment