sahat / hackathon-starter

A boilerplate for Node.js web applications
MIT License
34.86k stars 8.17k forks source link

Notes for Hackathon Starter 3.0 #179

Closed sahat closed 9 years ago

sahat commented 10 years ago

I will start the list for the possible upcoming changes.

Feel free to add or remove anything. Everything below is open for discussion.

nijikokun commented 10 years ago

I'd say utilization of a feature that Angular introduces: Factories & Services

Example would be the mailer:

var secrets = require('../config/secrets');
var nodemailer = require('nodemailer');

// Factory
function MailFactory (options, next) {
  nodemailer.createTransport({
    service: MailFactory.service,
    auth: MailFactory.auth
  }).sendMail(options, next);
}

// Mailer Settings
MailFactory.service = 'Mandrill';
MailFactory.auth = secrets.mandrill;

// Export
module.exports = MailFactory;

Using Angular as an example, just to show seperation of Business logic and view logic: Business logic in Controllers makes testing Services impossible.

sahat commented 10 years ago

@Nijikokun while your example may be great and all, it requires me to think how it works. That is true for almost any abstraction that is introduced into the code. Users who are not familiar with a Factory concept may be lost, and at that point it defeats the purpose of Hackathon Starter, which is to quickly get started a Node.js project at a hackathon.

I have received lots of feedback from others who are glad that Hackathon Starter's code organization is so simple and easy to understand unlike some other projects like MEAN.io, MEAN.js, et al. As you pointed out testing might be a little hard with the current setup but testing has never been a top priority for this project, simplicity and ease of use are.

nijikokun commented 10 years ago

The code would would be even simpler than it currently is.

Update I was barely awake, when I wrote the line above, and while true it doesn't fully expound upon the meaning or what I wanted to convey.

  1. By doing this you are introducing standards, and these standards should the hackathon project become realized as a viable thing, which often many do they have them in place already and refactoring would be minimized heavily.
  2. Testing. Testing. Testing. This reduces the friction to test your code, and have 100% test coverage.
  3. Good practices, the developers learn the right way to do things, and that is beneficial to everyone.
  4. Separation of business logic actually reduces code, and keeps things contained in one location generally. You change once and it changes across the entire codebase, reducing the amount of time required altering files and methods.

I could actually continue, but I think the benefits heavily outweigh something like: It's hard to understand, or familiarity.

You don't even need to convey the concept, simply, this is where your logic goes regarding commonly used components, not to mention minimizing repetition of what should be constants, such as emails, name of the site, and more.

If you don't want to introduce constants, I'd suggest app.locals to store site details before routing is invoked, this way you can easily manage your site name once without ctrl+f.

You can have simplicity without complexity. It's a matter of how you convey it.

bradsimantel commented 9 years ago

Has there been any more consideration of Hapi vs. Express?

sahat commented 9 years ago

@bradsimantel I have but I may keep Express after all. It's just too big of a change. There was one about Express vs Hapi and the guy named Hendrik Swanepoel posted this great response in the comments section:

I find that it's sometimes better to stick with a suboptimal tool, because you know it well enough. You know it's limitations, and you can code around it. You are not stuck on producing the most elegant code ever, with the best framework ever, you are concerned with delivering business value. If you've been using a framework like express for a while, you don't even see it anymore, your brain starts distinguishing between framework code and business code with less and less cycles. That is when you really start delivering business value.

Dakkers commented 9 years ago

it would be cool to see you implement sending emails to users after they sign up to confirm their account. I wrote a node module that allows you to do this pretty painlessly:

https://github.com/StDako/node-email-verification

vladimiry commented 9 years ago

What about using bower + gulp to manage web dependencies? In two steps: 1) "bower install" 2) copy needed files from bower_components to ['public/fonts', 'public/css/lib', 'public/js/lib'] After adding "bower install && gulp install" to package.json "postinstall", dependencies of all layers could be installed by one command "npm install". I use this approach on top of current version of "hackathon-starter", so "lib" and "fonts" folders are empty initially.

It also would be great to switch between DB types, at least mongo <--> postgres. But I understand that it's not easy to do without using complex ORM module, that able using general API to handle NoSQL and SQL databases as well. Actually I have replaced Mongo by Postgres (via Sequelize) in my last "hackathon-starter" based project, but Sequelize does not support NoSQL databases.

sahat commented 9 years ago

@vladimiry Bower and Gulp usage has already been considered. @dstroot created a project similar to Hackathon Starter called Skeleton using Gulp, Bower and etc. I use both Bower and Gulp for my other projects, howerver, for Hackathon Starter I want the barrier to getting started to be at minimum.

I knew someone who tried to create an abstraction layer of some sorts for Node.js that works seamlessly with Postgres, MySQL, MongoDB, and others, so that you can just plug it in and it magically works with all databases. It was very difficult and I don't think that project was every finished. I am fine with MongoDB because it is a popular choice among Node developers, just like MySQL is a popular choice among PHP developers and Postgres among Python/Ruby developers.

loris commented 9 years ago

@vladimiry @sahat Sails.js ORM, Waterline is a pretty popular one, and do support both SQL and NoSQL databases (An adapter-based ORM for Node.js with support for mysql, mongo, postgres, redis, and more)

vladimiry commented 9 years ago

@Ioris I've tried Waterline, it is very limited, and it seems that the authors have no plans to solve numerous issues. For example there is still no support for arrays (honest/true arrays, for Postgres for example) https://github.com/balderdashy/sails-postgresql/issues/36 So IMO at this time it is only suitable for the most simple tasks.