auto generate Rest service in node.js

2019-07-04 00:21发布

Is there a way to auto generate a Rest service in node.js like in rails? I just want to expose my mongodb models as a Restfull service. I am now doing a lot of repetitive work with Mongoose and express-resource.

2条回答
相关推荐>>
2楼-- · 2019-07-04 00:32

Yep, it's possible, follow this commands:

npm install railway
railway init rest-app && cd rest-app && npm install
railway generate scaffold resource property1 property2
railway server 3000

That's it! If you need to generate nested resource:

railway generate resource.nestedresource propertyForNestedResource

and modify config/routes.js:

map.resources('resource', function (res) {
    res.resources('nestedresources');
});

Check this example app: https://github.com/anatoliychakkaev/railway-example-app

Welcome to railway: http://railwayjs.com

查看更多
姐就是有狂的资本
3楼-- · 2019-07-04 00:36

You can also use a library I developed if Railway is too bulky for your needs:

https://github.com/enyo/mongo-rest

It's a simple library, well tested, that just provides a REST interface for your mongoose models.

查看更多
登录 后发表回答