Hacker News new | comments | show | ask | jobs | submit login
Crud-bones - Boilerplate project to kick-start your Node.JS/Mongo/MySQL CRUD app (alexeypro.com)
39 points by green on Apr 21, 2012 | hide | past | web | favorite | 14 comments

Is MySQL a common choice with Node.js? Don't see many people talking about SQL and Node.js. Anyone using this combo got something to say about their experience with it?

Hard to say if it's a common choice. I've had few projects where Node.JS was the choice of backend, and MySQL was the database, because our frontend was PHP/static HTML/CSS/JS stuff. DB is not really important. Node.JS shines on the backend, and it doesn't really matter to what it talks to. MySQL can be decently fast, but you can as well use Node.JS solely with, say, Riak or Mongo, or just Redis? In this "crud-bones" project I am use Redis as a cache layer, but you can use it as "storage" as well...

Interesting code. Have you thought about automatically creating the models by using SHOW TABLES + DESCRIBE? Might save you some time.

That's definitely something what I don't want to do. Not that it's bad, or something.. just it defeats the purpose of this app. The goal is to have some skeleton or base to start your own stuff. There is no reason to make it so flexible so it'll generate all that stuff. Besides, as you can see, my app works with Mongo or MySQL DB by simply changing ONE SINGLE LINE of the code. Which is kinda cool, I think. No ORMs, no special "preparations". A little bit work on the model class, and you are done.

Besides, I mentioned that already, we all know we are going to change this code for our own needs. So it needs to be simple, straightforward and interchangeable. That was my goal.

There should be something like this for every language. I've recreated this so many times in so many languages.

I am just getting in to node.js, I will have to try this and see if it makes things any easier.

I hope it will make things easier, or at least would server as a collection of code snippets "how to" :-) Let me know if you have any questions, or would like to have something beyond what you see there. Feel free to email me (http://alexeypro.com) or just simply contribute to the project. Thanks!

Just in time!

I am glad if you found it helpful, and happy I didn't sit on it.. yeah, it's far from been all shiny and polished, but the intention is to get basic Node.JS CRUD project up and running, so you can focus on actual project's goals, not (while simple but still time-wasteful) basic implementations. Especially if you need to wire together DB connections, Express, EJS, ...

Nice work!

Do you use any ORM for MySQL?

Actually, I don't -- I am trying to keep the app extremely simple, and straightforward. I don't want new Rails app, neither want Java-style-framework. All of us are going to cut it back and forth to make to suit our next project needs, so why bother?

The switch between using Mongo and MySQL -- is just using different DAO -- https://github.com/alexeypro/crud-bones/blob/master/src/api-... I kept the "interfaces" (yeah, not interfaces but contracts, 'cause JavaScript has no interfaces, but you know what I mean) same, and that makes the switch EASY.

In short-term plans I want to update README as for the deployment instructions to other Node.JS hostings, and probably throw some simple caching layer on top of Redis, and definitely some unit testing. Then it should be all set. Just basics to get me up & running with new backend effort :-)

Frankly, even those things are not necessary. They will make the app more complicated, but let's be honest -- we use Node.JS because it's lightweight and minimalistic approach, so why create an ugly-beast-which-does-it-all-its-own-way?

You can look into Sequelize. http://sequelizejs.com

Thanks. This is a huge help for me.

Let me know if you think it can be improved. I am happy to make it easier. :-)

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact