I am trying to schedule a function call via setTimeout
. The setTimeout
call is supposed to run when the module is instantiated. The code that goes inside the callback has nothing to do with the status of the server (port, host, etc...), for example:
fs.readFile(__dirname + "/file.json", "utf-8", (err, data) => {
if (err) throw err
// Some fetch operations using data
})
Should I be placing this code directly in the module's file or in the app.listen
callback? What are the differences, if there are, between code that goes inside a node.js module directly and code that goes inside the app.listen()
callback?
I have already read this post but couldn't find an answer.