When developing an API using nodeJS and express, 2 js file involved as below
When I pm2 start main.js, doSth() in api.js works as I expected, however, when I pm2 stop main.js, cleanSth() not working, anyone can advise how can I achieved my expected result (cleanSth when I pm2 stop)?
api.js
const express = require('express')
doSth()
const routes = (app) => { ... ... }
process.on('beforeExit', cleanSth()})
module.exports = routes
main.js
const express = require('express') const app = express()
const a = require('./api.js') a(app)