you're probably better off restructuring your code to not need it. Maybe create a third class that uses the other two to accomplish what you need, if you have to use a function in app.js
you can do like this:
before requiring you should exports express()
and functions
app.js
const express = require("express");
const func = () => {
console.log("I'm in App");
};
var exportFiles = module.exports = {
app: express(),
func: func,
};
var { app } = exportFiles;
const fs = require("fs");
const path = require("path");
const bodyParser = require("body-parser");
app.listen(8080, () => {
console.log("server port is 8080")
})
contolers.js
const {func} = require('../app');
when you call func()
in controller result is :
func() // I'm in App
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…