Question

Is there a way to use Chaplin with node.js/express? I haven't found a single tutorial or an example on this subject.

If so, how do I get started? How would the folder structure look like? Or my server.js file?

Was it helpful?

Solution

Chaplin appears to be purely client side. For a basic app your back end could be a static HTML page. It requires no particular server structure.

Backbone, which it's built on, expects a RESTful JSON API to persist its models, but otherwise doesn't require a backend either. If your app has models which need to be saved (likely), then you'll want to look into tutorials for writing a REST API in express (there are many) or for extending Backbone to suit your particular backend needs.

So to get started, your server.js file will look exactly like the one created by the express install script.

There's no de facto best practice for how to structure the folders in an end-to-end javascript app. In my experience I tend to keep client side javascript in its own folder (/client, /app/client, /lib/client, etc), then generate the publicly exposed compressed/concated scripts in a build step. To get started, you might just deposit them in /public/javascripts.

OTHER TIPS

I still don't understand this.. In my express file it says

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

Should I move all my chaplin app files into that views folders or how do I launch them? Anyway, express seems to use this jade thing but chaplin does not, how does that go?

My problem is to understand where everything goes and why.

Express creates it's own folder structure:

  • node_modules
  • public
  • routes
  • views
  • app.js

then again chaplin has it like this:

  • app
  • generators
  • bower.json
  • config.json etc.

in that app folder:

  • assets
  • controllers
  • lib
  • models
  • views

Now, where do I place all of this chaplin stuff in my node folders? under public or views or where? And then how do I get this whole thing started? Do I just include all the chaplin .js files in that index file I have in my node.js views folder (jade file)?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top