Tuesday 13 December 2016

Project setup/best practice for loading constants from files into Express/Node/React webapp

I'm trying to make a webapp with React, Express, Node, etc. I've been following this tutorial, and so have also been using Gulp, Babel, and Browserify. From what I understand of this, files I write are taken from app/ and get transpiled and bundled together into one js file and put into public/ for the Express server to serve, with the directories being specified in the gulpfile.I have a bunch of constants in a csv file that I want to be available to the webapp, without being hardcoded somewhere (so that I can just drop in an updated.csv on the server and have things work). So, I have a few questionsI tried including the csv files in public/ and reading the files client side (with d3-csv), but it seems like the files in app/ are getting run from the server, since the npm run watch console is outputting stuff and getting Error: connect ECONNREFUSED 127.0.0.1:80 errors? Is that supposed to happen? Or am I doing something wrong?My csv files aren't very large so it wasn't a problem, but if they were very large and I wanted to cut down on how much data was being sent, what would be ways of doing this without having to put the csv files in public/ somewhere as assets? Are my choices either A. Have the server load the constants, and then have the client make a call to pull them on load or something, or B. Somehow doing some weird pre-processing of the js files and edit the constants in?For option A in 2., where in my thing would I make the $.ajax call to the server in order for it to happen upon load - just at the beginning of main.js (before the ReactDOM.render call) or something? Thanks!(For specifics, the current (broken) repo is at http://ift.tt/2hBogK4)

Submitted December 13, 2016 at 07:07PM by colblitz

No comments:

Post a Comment