简体   繁体   English

如何使用node.js来运行react.js前端?

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

How to do get node.js to run your react.js front end? 如何获取node.js以运行您的react.js前端?

server.js 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? 这段代码可以很好地运行我的angularjs网站,但是要运行使用webpack + es6的react.js,我必须进行哪些更改?

You can have a look at it. 您可以看一下。 I have configured a starter for my react and redux project with node using webpack. 我已经使用webpack为带有node的react和redux项目配置了一个启动器。 Hopefully you will get an idea. 希望你能有个主意。

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

You can add the React package from the repositories of npm: https://www.npmjs.com/package/react 您可以从npm的存储库中添加React软件包: https ://www.npmjs.com/package/react

Just follow the instructions. 只需按照说明进行操作即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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