ReactJs how to combine react and express reactjs combine reducers,reactjs combine two arrays,reactjs combine two

I worked on my client and server side code separately. I now managed to get them both working simultaneously in the same project but i dont know how to makethe two work together. I am using javascript/node/react/redux/webpack on client side and node/express/jade on the server side.

index.js

import React from "react";
import { render } from "react-dom";
import { Provider } from "react-redux";
import { BrowserRouter as Router, Route } from 'react-router-dom';

import store from "./store/index";
import App from "./components/App";
import Home from './components/_HomePage';
import User from './components/_AboutPage';

render(
  <Provider store={store}>
    <App/>
  </Provider>,
  document.getElementById("app")
);

this loads up a react page on port 3000, where i can add stuff to a list.

server.js

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var index = require('./server/routes/index');
var users = require('./server/routes/users');
var catalog = require('./server/routes/catalog');

var db = require('./db/db');

var app = express();


// view engine setup
app.set('views', path.join(__dirname, 'server/views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
//app.use(express.json());
//app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'server/public')));

app.use('/', index);
app.use('/users', users);
app.use('/catalog', catalog);

// Connect to MySQL on start
db.connect(db.MODE_PRODUCTION, function(err) {
  if (err) {
    console.log('Unable to connect to MySQL.')
    process.exit(1)
  } else {
    app.listen(3001, function() {
      console.log('Listening on port 3001...')
    })
  }
})

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;

this file loads up the server on port 3001 , which can also be opened as a webpage. It connects my server side to a mysql database and presents the information there on the webpage.

So now i have these 2 webpages, which can run simultaneously, but how do i create 1 page from that?

i am using jade views, so im guessing that my server is going to have to provide these jade views together with database data. And i should forget about the sever side page and just treat it as a service to the client side?

Answer:1

You can use Express for the backend (Rest API) and React for the frontend (you can access the API using package like Axios, superagent, etc)

Answer:2



  1. reactjs combine reducers
  2. reactjs combine two arrays
  3. reactjs combine two classes
  4. react combine styles
  5. reactjs combine arrays
  6. reactjs combine objects
  7. react combine style objects
  8. combine reactjs native

I am developing a webapp in reactjs using typescrpit in visual studio 2017, which is very new technology for me. I am stuck at a problem where i dont know how to re-render a component from another ...

I am developing a webapp in reactjs using typescrpit in visual studio 2017, which is very new technology for me. I am stuck at a problem where i dont know how to re-render a component from another ...

I've taken over a React project and am fumbling incorporating react-share with react-image-lightbox. I'm pretty unfamiliar with React and Typescript all together so any insight is much appreciated. ...

I've taken over a React project and am fumbling incorporating react-share with react-image-lightbox. I'm pretty unfamiliar with React and Typescript all together so any insight is much appreciated. ...