Is there anything in Node.js like scaffold in Rails? [closed]
I guess it depends on what you want:
- Rails style code generation (where it generates code for you that you can modify)
- Django style semi magic where admin forms can be derived from the fields in your table/document schema.
- you mean generating an API for these fields in the database, ala what grape does for Ruby -- you do some configuration and translating data to JSON and transmitting it back over the wire is taken care of for you
- You have a new project and you're looking for a framework with one of these three characteristics
For the first three options there are a few related SO questions on this already:
There are a few awesome answers in this set of links, including:
- @jsalonen's answer gathering up some tools <-- mostly about generating admin UIs
- @Dow's answer with some tools <-- he mentions RailwayJS (now CompoundJS), then points to some other SO questions/answers on this topic.
- @bergie's answer about a module that exposes JugglingORM models as RESTful API routes automatically
- Or, as @Andbdrew mentioned in the comments, there's node-restify
- You could write your own generator - perhaps you could write a Cake task that would take a template file, execute some Javascript and output a view for your application. I started down this path recently myself. Certainly with the variety of technologies Node.js apps involve (different ORM choices, Javascript front ends, CSS layouts) this may make sense.
For the last option - an opinionated rapid web development Node.js framework that provides good API support, there are a few options:
- @abject_error's answer, in this question, about Sails
- Geddy <-- automatically provides .json versions of the data your controller specifies (depending on the request it uses this data to render HTML views or creates a JSON representation)
- There's a nice slide-show on How to quickly make REST APIs with CompoundJS, so CompoundJs may fit your tastes.
I initially left these off as I assumed you may have an existing project, or didn't want to use an opinionated framework, but added them because why not.
SailsJS (https://github.com/balderdashy/sails) is exactly what you're looking for. It uses the Waterline
module for simulating ActiveRecord
. Just define a resource, and it will automatically create JSON endpoints for all RESTful actions, and also makes the endpoints compatible with Socket.io connections.
It's built on Express, so you can use any Connect middleware to extend it. AFAIK it's the best NodeJS framework
for building API backends.
Defining a new resource is as simple as sails generate user
. This will create the appropriate model and controller files, which you can then modify.
Keep in mind Sails was built with schema-less datastores in mind, so it's primary support is for MongoDB, not MySQL. I'm not sure how well (if at all) it supports SQL databases.