How to integrate ReactJS with expressJS

Firstly, I am very new in ReactJS. I completed a simple reaction project based on the following link. http://www.tutorialspoint.com/reactjs/reactjs_environment_setup.htm and I can work fine and check by doing " npm start". But when I try to integrate with expressJs as editing / development, following the coding, I can not display at all.

Package.json

  "scripts": {
    "start": "node server.js"
  }

server.js

var express = require('express');
var path = require('path');

var app = express();

var isProduction = process.env.NODE_ENV === 'production';
var port = isProduction ? process.env.PORT : 3000;
var publicPath = path.resolve(__dirname, '/');

// We point to our static assets
app.use(express.static(publicPath));
console.log(publicPath)

// And run the server
app.listen(port, function () {
  console.log('Server running on port ' + port);
});

Whenever I show as " npm start", meet as follows.

Impossible GET /

+4
source share
2 answers

api js, index.html

app.get("/", function(req, res){
    res.sendFile(dirname + "index.html");
})

.

+1

, @Shubham Khatri, , . - , React, .. http://appDomain.com/products http://appDomain.com/blog http://appDomain.com/articles, .

, Express ( , root /).

React Express , Express , 7070.

React Replace , 8080. React Express Routes, Urls API .

/, , : ReactJS, , ExpressJS

0

Source: https://habr.com/ru/post/1653100/


All Articles