I've coded an React Application in ES6 style, all my Components are build like the following:
import React, { Component } from 'react';
class Test extends Component {
render() {
return (
<div className="testDiv">
Hello Word
</div>
)
}
}
export default Test;
This website is running via the default configuration via "npm start" at port 3000.
Furthermore I've an nodeJS application with an API via expressJS on port 8080. Now I want to create an single route to express where I can render the React application and deliver the HTML String back to the client. What's the best way to do this ? I'm new to React development, hope somebody can help.
Here's a minimalistic example how to render your Test component on an Express server:
import express from 'express';
import Test from './Test';
import React from 'react';
import ReactDOM from 'react-dom/server';
const app = express();
app.get('*', (req, res) => res.send(ReactDOM.renderToString(<Test />)));
app.listen(8080);