#how to pass data from expressjs route to nextjs file

17 messages · Page 1 of 1 (latest)

south shale
#

I'm transitioning from ejs to nextjs, in ejs you can pass data on request while rendering. Can we do that in nextjs too ?

queen vale
#

Can you elaborate?

south shale
# queen vale Can you elaborate?

Ok so while using expressjs for server I could pass data on a user request to my ejs template and the html page was rendered in the server can we do something like this with nextjs too ( I'm thinking to use expressjs and nextjs together)

coarse marlin
#

You can do that with server component.
If you run a fetch in server component (or any logic you need to run before rendering it), it will be returned in a variable which you can pass to child components

south shale
queen vale
#

Not sure what you mean by routes file

#

But any data is gathered in the page.tsx file and passed down to components

coarse marlin
coarse marlin
queen vale
#

I think he was referring to something with express routes

#

Not sure

coarse marlin
# queen vale I think he was referring to something with express routes

yeah in express routes we were used to handle the GET request, do some app logic, then render the pages..
im explaining that in nextjs, the page rendering route is different from traditional GET route handler...

so if you want to handle GET request to perform page rendering, you have to use the page.jsx
but if you only want to handle GET request to return a data, use the route.js
you can't use both at the same route/filepath

#

i hope that make sense

queen vale
#

Other routes make work though idk

#

Like post or put

#

I have 0 clue

coarse marlin
#

If we use post or put it would definetly not for rendering page so thats out of the question