Rendering a ReactJS application on the server-side is referred to as Server-Side Rendering (SSR). This can increase the performance of the application because the browser can start rendering the HTML from the server without having to wait for all the JavaScript to be loaded and executed.
Here is an example of how you can render server side with ReactJS using ExpressJS as the server:
1. Install the necessary dependencies:
- ExpressJS: `npm install express`
- ReactJS and ReactDOM: `npm install react react-dom`
1. Create a new file `server.js`, which will host the Express server:
```
const express = require(‘express’);
const React = require(‘react’);
const ReactDOMServer = require(‘react-dom/server’);
const App = require(‘./App’); // Assuming you have an App component in current directory.
const app = express();
app.get(‘/’, (req, res) => {
const html = ReactDOMServer.renderToString(
app.listen(3000, () => console.log(‘Server is running on localhost:3000’));
```
1. Start the server with `node server.js`.
1. Open a web browser to `http://localhost:3000` to view your server-rendered ReactJS app.
Note: This is a very simple example of server-side rendering in React. A real-world application would normally involve more complex tasks such as handling initial data loading, managing state between the server and client, and configuring webpack/Babel for server-side code. You might also want to use a library like `react-router` to handle routing.