简体   繁体   中英

how do use node.js to run react.js front-end?

How to do get node.js to run your react.js front end?

server.js

 var express = require('express');
    var path = require('path');
    var logger = require('morgan');
    var cookieParser = require('cookie-parser');
    var bodyParser = require('body-parser');
    var mongoose = require('mongoose');
    var bcrypt = require('bcryptjs');


    var app = express();


    // links the node server to the webpage
    app.use(express.static(path.join(__dirname, '../public')));



    app.set('port', process.env.PORT || 3000);
    app.use(logger('dev'));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded());
    app.use(cookieParser());

    app.listen(app.get('port'), function() {
    console.log('Express server listening on port ' + app.get('port'));
   });

this code runs my angularjs site fine but what changes do I have to make for it to run an react.js that is using webpack +es6?

You can have a look at it. I have configured a starter for my react and redux project with node using webpack. Hopefully you will get an idea.

https://github.com/OnlyRefat/react-redux-webpack

You can add the React package from the repositories of npm: https://www.npmjs.com/package/react

Just follow the instructions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM