-2

Is there a full-stack, NodeJS-based framework similar to Ruby on Rails or PHP which renders templates on the server-side?

Basically, I am wanting to develop a web site which will be indexable by Google (non-SPA). I'd like to be able to include common header and footer files on each page. I basically want to do the following but with NodeJS:

index.html:

<?php include 'header.php'; ?>

<h1>This is the home page</h1>
<p>Here is some content.</p>

<?php include 'footer.php'; ?>

I will not be using a RESTful API (or any API) for this web site. It's basically a simple, static web site which uses NodeJS for its server-side component.

Chad Johnson
  • 21,215
  • 34
  • 109
  • 207
  • 8
    express+jade or express+ejs or express+anyothertemplatingengine – Mukesh Soni Mar 16 '14 at 06:02
  • For static site generation I can recommend [assemble](http://assemble.io/). Only a few days ago I've encountered [metalsmith](http://www.metalsmith.io/) which might be a bit easier though seems to be quite young. – hgoebl Mar 16 '14 at 09:28
  • 1
    I think this question is downvoted because it doesn't fit well to questions here on SO. Answers to your question are not solutions to a problem but must be opinionated and there is no single correct answer. It's very sad that SO does not offer a way to get opinions. If you ask on reddit you won't get good answers like here. – hgoebl Mar 18 '14 at 14:13
  • I agree. At some level, every question and answer on Stackoverflow can be argued to be opinionated and subjective, at some level. Needless to say, I will be using Reddit more often now. – Chad Johnson Mar 18 '14 at 17:30

3 Answers3

2

I would suggest that docpad is the best solution at the moment for what your looking for. It allows you to setup a set of templates, content and styles which generate a static site for you.

You select what templating engine that you would like to use based on a plugin system. The tutorial (which I followed recently) explains very easily how to do what you would like to do. The tutorial uses eco templating engine. Now I knew nothing about eco and was able to follow and figure out some tricky requirements of my own without too much trouble.

If you go this route, then I also suggest the partial plugin, which is really nice for inserting bits into other bits.

Start here on how to use. It takes you through everything that you could need to know for using it.

I also suggest installing node.js as per these instructions.

Community
  • 1
  • 1
Metalskin
  • 3,998
  • 5
  • 37
  • 61
1

If you have experience with Backbone.js, Rendr.js shows some promise.

Josh C.
  • 4,303
  • 5
  • 30
  • 51
0

Your best bet is to just use one of the simple frameworks like Express http://expressjs.com/, along with a simple templating engine like Handlebars.

This module is then the one you need to add to the project:

https://github.com/ericf/express-handlebars

The readme of this is excellent, and has some fully working examples showing your two options:

  1. Use a global layout file (this will have your header and footer in it).
  2. Use partials - similar to the php example above

Keep in mind that the default Node world is to do server side rendering,just the same as PHP, but in JS. The frameworks like rendr are really trying to do something much more complex, and share rendering between server and client - you don't need this if you are just building a simple web site.

Best of luck.

cliftonc
  • 567
  • 4
  • 8