51 ms·
I've been looking at Node recently and I'm struggling to get my head around the run both on server and client methodology. I understand why it's useful to defin
by RossM 14y ago
I've been looking at Node recently and I'm struggling to get my head around the run both on server and client methodology. I understand why it's useful to define model classes and include the file in both places, however I don't really see how this extends to the rest of the app. This tool seems to imply that you join all the modules of the app together into one file, which you can then include on the client - but surely there'd be code that you don't want included in this (like the server-side of websocket communication)?
Does anyone have any articles that can help me to fill the gaps?
- combataircraft 14y agoA bundle file OneJS generates contains only a tiny CommonJS implementation and a simple "process" object ( use "--noprocess" option if not needed). You can browse them here; https://github.com/azer/onejs/tree/master/templates https://github.com/azer/onejs/tree/master/templates It doesn't contain the standard library of NodeJS by default but you can install the available modules like assert, path, url etc.. by doing: $ onejs install assert
- Lazare 14y agoThere's two separate issues here. 1) "Hey, how can I use the same code on the server and the client?" Hard problem, but you can look at Meteor or Derby for people working hard to solve it. It's unrelated to this project though. 2) "Hey, I've been using npm and require and coffeescript to write some cool code, but I want to run the entire thing in the browser. How can I somehow "bake" this all down to a single JS file I can deliver to the client where everything just works? This is a pretty easy problem, and it's been solved by Stitch (my favourite), Hem, Browserify, and probably a few more. And now, OneJS. :) If it helps to see an example, I'm working on an app with a really big complicated source code tree; it's split into lots of files, plus a bunch of libraries, some of which are "traditional" JS libraries like jQuery, and some of which are "modern" CommonJS modules installed by npm. I use Stitch to bundle the whole thing into a single application.js file which contains every bit of my client-side code (only). My HTML file only contains two script blocks. <script src="application.js"></script> <script> app = require('app'); $(function(){ app.run(); }); </script> That's all it takes to load all my client side code - including all libraries - and then kick off the initialization code once the DOM is ready. I'm using Stitch, but I believe OneJS is designed to do the same thing. I'm afraid I find the documentation on the project really hard to follow though, so I might be wrong. :)
- combataircraft 14y agoFOA, "using same code" means "sharing same source code in all JS environments" in this context. "Proxying some server-side JS code to client-side" is totally irrelevant to this topic, as you pointed. And here are the differences of OneJS: - it produces unobtrusive code - it bundles any level of dependency properly - it's not only for web browsers, but also all JS environments including Node itself - it's a command-line tool that doesn't require you to code.