NodeJS modules
To separate functions and the code calling them into separate files you use modules. That allow functions to be reused, as they can be called from various different files.
Let’s create a module.
Change the code in your greet function to look like this:
module.exports = function(name){
return 'Hello, ' + name;
}
Now to use this newly created module, create a new file called greet_xola.js - try this code in that file.
//import the greet module that is in the current folder
const greet = require('./greet');
console.log(greet('Xola'))
Run it using NodeJS, node greet_xola.js. You should see the same output as before.