I have an NodeJS/Express app with several route files in /routes folder. I would like to be able to call a function on a server side i.e. myfunction.js from any of route files. What is the best way to set it up. As of now, i have myfunction.js duplicated in each of route files.
            Asked
            
        
        
            Active
            
        
            Viewed 82 times
        
    0
            
            
        - 
                    require function in all route ?? – xdeepakv Apr 16 '20 at 16:14
- 
                    1You mean something like `const myFunction = require('./utils/myfunction.js')`? Create a separate file for your utility function and import it wherever you need it - https://stackabuse.com/how-to-use-module-exports-in-node-js/ – goto Apr 16 '20 at 16:16
- 
                    @goto1. Yep somthink like that. Thank You. – goryef Apr 16 '20 at 16:34
- 
                    @goto1. That's seems like exactly what I need. Thank You – goryef Apr 16 '20 at 16:43
