Exporting functions/ objects in a NodeJS + Express route file


0


In general NodeJS router files looks like following, where we create router and add endpoints to it and export the router.

api.js


and in the server.js or index.js file we wire it using the following code

index.js


But in some cases, we may want to return functions or objects from the same router file, we can achieve that using the following code.

api.js


index.js