A Reptilian
A Reptilian
TTCTheo's Typesafe Cult
Created by A Reptilian on 6/27/2024 in #questions
Most efficient monolith structure to have an Express.js REST API with Next.js SSR client?
https://stackoverflow.com/questions/78670127/most-efficient-monolith-starter-project-structure-to-have-an-express-js-rest-api Hi there! I'm starting a fulltack JS application, but would like to know your opinions on how an express.js server should be set for a Next.js frontend (Next.js API development is not an option for this purpose). I wonder if the following would be an appropiate approximation:
/project
|-- /node_modules
|-- /client
|-- /server
└- package.json
/project
|-- /node_modules
|-- /client
|-- /server
└- package.json
In tutorials I usually find the instruction to:
/project
|-- /client
| |-- /node_modules
| └- package.json
|-- /server
| |-- /node_modules
└ └- package.json
/project
|-- /client
| |-- /node_modules
| └- package.json
|-- /server
| |-- /node_modules
└ └- package.json
I'm not certain on how this would work in production either as I don't have experience in deployment or integration. Should the client and server process run as 2 different runtime threads or should a single index.js handle everything under a single mode_modules library for monolith. Something like... index.js
const app = express()

// Maybe run Next
app.get('/', (req, res) => {
// Run Next SSR like...
// res.send(next????)
})

app.get('/api', (req, res) => {
res.status(200)
.json({ resource: "value" })
})

app.listen(3000, () => "Express listening on port 3000")
const app = express()

// Maybe run Next
app.get('/', (req, res) => {
// Run Next SSR like...
// res.send(next????)
})

app.get('/api', (req, res) => {
res.status(200)
.json({ resource: "value" })
})

app.listen(3000, () => "Express listening on port 3000")
Appreciate your review and advice as I'm just an amateur programmer!
4 replies