I've tried different ways to search for this and I am coming up with nothing. When setting up an express app and importing a file of routes you often see documentation for this statement:
require('./app/routes/posts.routes.js')(app)
Which from the documentation in nodejs.org means to require the file './app/routes/posts.routes.js' and run everything in the app object.
What I have not come across is how to write this statement using "import".
My example:
Route File Contents
module.exports = (app) => {
import posts from '../controllers/post.controller.js'
app.post('/posts', posts.create);
app.get('/posts', posts.findAll);
app.get('/posts/:postId', posts.findOne);
app.put('/posts/:postId', posts.update);
app.delete('/posts/:postId', notes.delete);
}
Import Statement
//this does not work throws Error: Cannot find package 'app' imported from /Users/matt1/socialbulk/server/server.js
import posts from 'app/routes/post.routes.js' //what do you do with (app)?
app.use('/posts', posts)
app.listen(3000, () => {
console.log("Server is listening on port 3000");
});