I have a server.js with my code, and I have a connection.js to connect to MongoDB databases. I would like to know how to run another file from my server.js. Currently, connection.js does not run.
It doesn’t run because you haven’t included it in your main file. You can include files using
require("./path/to/module")
or
import "./path/to/file"
Also, you can export variables, functions, etc. from your module:
// if you used require()
module.exports.foo = bar
// if you used import ""
export default const foo = bar
More about import / export: https://javascript.info/import-export