call node js function from javascript

  1. In your Node.js file, define a function that you want to call from JavaScript.
  2. Export the function using module.exports so it can be accessed outside of the file.
  3. In your JavaScript file, require the Node.js file that contains the function using the require keyword.
  4. Call the function using the required file's reference followed by the function name, passing any required arguments.