简体   繁体   中英

Setting up a React app with Express

My first time posting here and I am completely new to web development so I apologise in advance if there is something similar on here already (I have had a good search)!

In short, I am making an app that fetches images from Instagram based on the users search input. Pretty easy. However, I am using Node and Express server side and React client side and I have googled many React tutorials, Express tutorials and I am confused as to how to even get started. Each tutorial uses different dependancies (which I have tried to Google and understand what they do) and are not explicit sometime as to where to put the code - I have seen app.js, server. js, templates.jsx. Hopefully, someone can explain in layman terms that helps us newbies.

So basically, I'd like some idea of how to set up my app and what files I will need eg app.js contains this code, server.js contains this code etc so that at least something shows up on my page.

So far I have this:

// in my app.js

var express = require('express'),
    app = express();

app.use(express.static('public'));

app.get('/hashtag/:hashtag', function(req, res) {
  var token = (removed);

  // this is where id fetch instagram imgs

});

var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;
  console.log('Instagallery server listening on http://%s:%s', host, port);
});

Thank you very much for any help/information!

Late to the party, but this tutorial provides an overview of setting up React with Express and may be useful for others experiencing similar frustrations.

https://medium.com/front-end-developers/handcrafting-an-isomorphic-redux-application-with-love-40ada4468af4#.yjzuy2k97

In case any beginner is just looking for only connectivity between react and express then this would be a trimmed down and easier to get started version without babel, testing tools and other not so initially required boilerplate.

https://medium.com/@kushalvmahajan/i-am-about-to-tell-you-a-story-on-how-to-a-node-express-app-connected-to-react-c2fb973accf2

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