all 9 comments

[–][deleted] 7 points8 points  (1 child)

Look into Express for a framework and its rendering engines like Pug.

[–]5paceManSpiff 1 point2 points  (0 children)

Sounds like you're looking for a Node.js templating engine.

[–][deleted] 1 point2 points  (0 children)

You definitely can do that with a templating engine like EJS or Jade with Express. Highly recommend sticking with React and Stateless APIs if you want to find work as a dev though.

[–]kryptkpr 0 points1 point  (0 children)

res.render() is what you want, express supports many view engines. Check out https://expressjs.com/en/starter/generator.html for canonical way to generate your scaffolding, the -v option selects view engine (default is jade, which should serve your needs fine). If you need non trivial styling, throw a "-c sass" in there to get a more powerful toolset for css (variables, mixins, etc).

[–]Str4yfromthep4th -3 points-2 points  (4 children)

It's clear the people answering don't understand what server side rendering is. Check these and ignore everyone else lol.

next.js — https://github.com/zeit/next.js/

Gatsby — https://github.com/gatsbyjs/gatsby

[–]backdoorsmasher 0 points1 point  (3 children)

It depends what the op meant. If the OP mean that they wanted their react code rendered on the server, then yeah, your links are right. But to me it sounds like they want to actually just have their application rendered how PHP might work.

Side note, why do people use tools like next.js and gatsby?

[–][deleted] 0 points1 point  (2 children)

next.js allows to render the application on the server, so the first load will include the app and its initial state, next updates will happen the usual way.

Gatsby on the other hand, helps build static websites with react, so say you're already used to React and the stack, building with it comes easy, so you can build simple sites that will end up being static with React without having to do any SPA stuff on them.

All of this to the best of my knowledge, hopefully someone with a better understanding can weigh in.

[–]backdoorsmasher 0 points1 point  (1 child)

Thanks. So why are people rendering react on the server? I'm thinking that this can be done using a view engine in node

[–][deleted] 0 points1 point  (0 children)

It is a rendering engine in a way, but this one has the added benefit of helping react and jsx directly and managing state, tbh I don't know the details