Live data from Hacker News

Create a character voting app using React, Node.js, MongoDB and Socket.io

sahatyalkabov.com

51–59 of 59 posts

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#51

Swig seems superfluous in that stack given it already has React, one could just use React to prerender the pages.

Personally, the only things I had to do to prerender full pages with React were:

- prepend '' to the resulting HTML

- attribute "prefix" in head tag "" wasn't outputted, so until it's fixed in the library, I just use a data attribute "data-replace-prefix" and removed the extra "data-replace-" from the resulting HTML

-------

Also, he could include inline scripts (like Google Analytics) this way:

  return ;

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#52

Christ on a bike... I spend a reasonable amount of time developing and maintaining a reasonable sized js based front end to an application, which uses React heavily (40k lines). Looking at this, I can't help but think that isomorphic JS apps make life far more miserable than separate back and front end applications. To get a decent server running on a linux distro - Nginx, Mariadb, PHP/Python/etc. An apt-get and your…

> It's insane that people think you need to do all this just to get a live updating counter. Dismissing this guy's tutorial because he didn't clone Facebook is kind of short sided. Everything is about trade offs. You don't need to make your React app isomorphic if you don't mind a slower initial load and lack of SEO. You don't need to use Mongo, you can pass data from your RDBMS directly to your components as props w…

Don't get me wrong, it's a massively comprehensive piece of work. I'm jealous of the author's chops - they know more about this than I do. But after all this time writing applications small and large, doing isomorphic JS dev feels like a massive step back.

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#53

Christ on a bike... I spend a reasonable amount of time developing and maintaining a reasonable sized js based front end to an application, which uses React heavily (40k lines). Looking at this, I can't help but think that isomorphic JS apps make life far more miserable than separate back and front end applications. To get a decent server running on a linux distro - Nginx, Mariadb, PHP/Python/etc. An apt-get and your…

Can you elaborate on you stack and toolchain? I'm curious about what's simple and works well with React.

For sure. The stack is designed to make hiring and maintaining simple, rather than to be completely elegant, so with that in mind:

Server is Nginx. Evaluating HHVM for migration is an ongoing concern, but there's some edge cases we run in to where it does wonky things. That said, within the next ~12 months, I expect we'll be on it.

MariaDB, with query results cached on Memcache. The data we deal with is massively relational, with some very large tables and result outputs, so there's no way around using a tidy RDBMS for us, and consistency is a big thing.

PHP, with a few tiny, high speed libraries for DB connection management and routing. As far as possible everything uses PHP functions that map directly on to underlying language equiv, and we make a lot of use of streaming and generators, which makes memory overhead nicely manageable. When HHVM becomes a thing for us, we'll then start pulling some of this over to Hack.

That's all set up as a bunch of RESTful APIs, which are reasonably HATEOAS in their outputs. Output format is either JSON or HTML, depending on request params.

Front end is a bunch of React bits. We're slowly converting into React, so initially we used HistoryJS to manage URL history, along with React to render stuff. Qwest for XHR handling, and a few little libraries and helper functions (of note: moment.js and numeral.js).

Everything then gets executed on the client. Current roadmap is to build something akin to React router for managing loading of assets and better history management, and to pull the entire front end into a single application. At the moment, it's better thought of as a bunch of distinct SPAs, operating over a common middleware.

Architecturally, the back end services are written MVA, with data going through our own DAL, with RBAC sitting in front of everything. Caching is handled in the DAL, so everything acts as a black box - models don't know where the data came from, adapters don't know where the model got it's data etc...

The front end is written loosely around a Flux style architecture. Data is held in a single area, as are all methods that interface with state. Those parts sit at the top, and pass data as props down to UI components, written to be dumb as to where there data comes from.

IO is mostly via single HTTP requests, but with the option to hook onto ZMQ for real time interaction.

Hope that helps! I'm currently writing some lower level thoughts on React on our blog (https://builtvisible.com/blog/) with some more advanced stuff coming shortly.

Apologies for the various TLAs. If you need anything explaining further, shout.

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#54

Earlier quoted context omitted.

Can you elaborate on you stack and toolchain? I'm curious about what's simple and works well with React.

For sure. The stack is designed to make hiring and maintaining simple, rather than to be completely elegant, so with that in mind: Server is Nginx. Evaluating HHVM for migration is an ongoing concern, but there's some edge cases we run in to where it does wonky things. That said, within the next ~12 months, I expect we'll be on it. MariaDB, with query results cached on Memcache. The data we deal with is massively rel…

It's a shame the blog of yours doesn't have a RSS or Atom feed.

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#55
post #50

I challenge your assumption that gulp + browserify is more straightforward than webpack. Your setup is not representative of a real application. I setup a project scaffold [0] with a configuration that supports development, production, and testing environments. It has a heavily commented webpack config. No tests? No asset cache busting by updating name references? Come on, those are basic requirements for a web proje…

Thanks for your project template. It looks really polished. What is your experience in regard to running tests with Webpack? * Can you test individual modules that use arbitrary loaders specified in your Webpack config? * Can you run tests from the command line? * Can you write your tests in ES6/7 (or anything else supported by Webpack's loaders)? I was looking into combining jest with Webpack but every solution so f…

No huge issues with running tests that depend on webpack, but the developer UX is not outstanding.

If you want to be able to do everything, you'll have to configure more stuff. Honestly, I don't think it's worth the extra effort to try and configure things to work with every possible workflow. Just setup what you need, and then add stuff in as you find yourself wanting / needing it.

My advice is to avoid jest. It's too slow and clunky. If you want to stub modules, there's rewire-webpack. If you're using babel and ES6 modules you'll probably want to check out babel-plugin-rewire. I think there's a few other alternatives, but I haven't had the need for any of these so far.

On to your questions...

> Can you test individual modules that use arbitrary loaders specified in your Webpack config?

Yes. The solution I have is to maintain a single webpack config maker function that has a bunch of conditionals inside, and then I just use that function from all my configs. When you set options.TEST to true, it'll set the entry point to an empty object.

That means that my tests will be configured as close as possible to my production and development. The same loader config will be used for all the environments.

> Can you run tests from the command line?

Sure. In the web-app repo, it uses karma with phantomjs.

If you want to test your code using node... It's a bit more annoying, but also doable. I've previously set it up like this: create a test.js [0] file, set it as the entry-point in the webpack config, and use webpack context to include all the tests you wanna run, and finally point mocha to the output file. If you wanna use it in "live" mode, you can run webpack and mocha both with the watch flag.

If you just wanna run a single test... You can specify a single test as your entry-point, and then point mocha to it. Again, if you want "live" mode, you can set the watch flag on both mocha and webpack.

> Can you write your tests in ES6/7 (or anything else supported by Webpack's loaders)?

Yes. They use the same loaders as the rest of your codebase.

[0] https://www.dropbox.com/s/35ebqijrp9nqyj3/Screenshot%202015-...

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#56

Christ on a bike... I spend a reasonable amount of time developing and maintaining a reasonable sized js based front end to an application, which uses React heavily (40k lines). Looking at this, I can't help but think that isomorphic JS apps make life far more miserable than separate back and front end applications. To get a decent server running on a linux distro - Nginx, Mariadb, PHP/Python/etc. An apt-get and your…

> It's insane that people think you need to do all this just to get a live updating counter. Dismissing this guy's tutorial because he didn't clone Facebook is kind of short sided. Everything is about trade offs. You don't need to make your React app isomorphic if you don't mind a slower initial load and lack of SEO. You don't need to use Mongo, you can pass data from your RDBMS directly to your components as props w…

[deleted]

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#57
post #35

Christ on a bike... I spend a reasonable amount of time developing and maintaining a reasonable sized js based front end to an application, which uses React heavily (40k lines). Looking at this, I can't help but think that isomorphic JS apps make life far more miserable than separate back and front end applications. To get a decent server running on a linux distro - Nginx, Mariadb, PHP/Python/etc. An apt-get and your…

There is just a lot of friction. Want es6, get ready to put gulp in your work flow. Want to sanely include frontend dependencies? Time to add throw in bower. Want those js/css to be injected into the page? Throw in wiredep or bite the bullet and chuck in the wirepack.conf.js. Don't want that and want to use a skeleton? Install yeoman and run the isomorphic js generatior that gives you a 1k+ line project and you haven…

jspm can actually remove a lot of the friction you mentioned:

1. seamless ES6 transpilation at runtime (no build steps needed)

2. load libraries in any package format as ES6 modules (Globals, CommonJS, AMD, ES6) from any source (local repo, Github, NPM)

3. no need for injection (you can import css and html programmatically using extensions)

It does introduce some friction of its own due to it being a relatively new project, but not enough to offset all the benefits it brings, in my experience.

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#58

Christ on a bike... I spend a reasonable amount of time developing and maintaining a reasonable sized js based front end to an application, which uses React heavily (40k lines). Looking at this, I can't help but think that isomorphic JS apps make life far more miserable than separate back and front end applications. To get a decent server running on a linux distro - Nginx, Mariadb, PHP/Python/etc. An apt-get and your…

Can you elaborate on you stack and toolchain? I'm curious about what's simple and works well with React.

Not the OP but I've really liked working with the Django REST Framework. Top-notch work and I suspect it would scale pretty well to a point.

Re: Create a character voting app using React, Node.js, MongoDB and Socket.io

#59
post #58

Earlier quoted context omitted.

Can you elaborate on you stack and toolchain? I'm curious about what's simple and works well with React.

Not the OP but I've really liked working with the Django REST Framework. Top-notch work and I suspect it would scale pretty well to a point.

Django is pretty nice. A little heavy for my liking (I prefer libraries to frameworks), but as frameworks go, it's a solid one.
Post reply on HN