I have an Express-server with routes and functions, that i would like to segment into seperate files. I understand this question has been posted hundreds of times, but after browsing through 20+ threds and guides I still can't manage to find a good answer.
I have a situation that looks like this.
function securityCheck(){
do stuff...
}
function anotherFunction(){
do stuff...
}
app.get("/login", (req,res)=>{
if (securityCheck()){
do stuff...
})
app.get("/backend", (req,res)=>{
if (anotherFunction()){
do stuff...
})...
and I would like to have it like this
embed(./securityCheck.js)
embed(./anotherFunction.js)
embed(./login.js)
embed(./backend.js)
...
I understand that module.exports can pretty much do this.
However, since it's evaluating code from the relative directory of the module it self, it causes issuse with dependencies. If i use for example the securityCheck() function I have to require that locally in the module, and it also makes me reorganize my paths.
I don't have any need for the modules functionality.
Im not looking for smart ways to reuse functions or make the project modular. I just want do segment my code for the purpose of cleanliness.
The thing im looking for is something like Eval, that just runs code in it's current context that would basicly import a textfile with the code in it.
Is this possible with Javascript and Node?