/coffeestack

CoffeeScript nodestack website and APIs made easy

Primary LanguageCoffeeScript

NOTICE

This project need a real re-thought. Currently it does too many things and needs to be splitted in many parts. I firmly believe that a proper JSON API server in order to be maintainable and easy to use needs to leave all the part of HTML generation outside its core. Trying to deal with content negotiation at the API level brings lots of extra complexity to your code and break the single responsability principle in many ways, which was one of the fundamental reasons why I started writing CoffeeStack in first place.

CoffeeStack

Node.js framework for web sites and web services based on a Domain model.

Why using Coffeestack

  • Rapid Application Development for model based webservices in top of web sites (Single backend code to make API and web site)
  • Achieve separation of concerns and code responsibilities with layered architecture (stop dumping code into the controller!)
  • Using MongoDB as main data/session store and plugin other sources if you need to (file storage, NoSQL and Relational can live together)
  • Create unit and functional testable applications (make testing your app fun)
  • Validate inputs against the Domain Model (stop copy and paste rules into external validators or controllers, creating ONLY valid objects to pass down to the stack)
  • Log errors, info and debug separately using bunyan

What is part of CoffeeStack

Updates status using David-dm

Dependency Status

Ready to go

Download the code to create an initial web application setup and extend it as you wish.

git clone git@github.com:fabriziomoscon/coffeestack.git

Requirements

sudo npm install -g ciao
sudo npm install -g mocha
sudo npm install -g coffee-script
sudo npm install -g bunyan

Setup

From the command line:

npm install
[sudo] npm install -g supervisor

Start Server

npm run supervisor | bunyan

Browse localhost

http://localhost:3000/

Run Tests

Build Status

npm test

Functional test using ciao

install ciao globally

sudo npm install ciao -g

load fixtures

curl -XPOST http://localhost:4000/testing/drop
curl -XPOST http://localhost:4000/testing/fixtures
curl -XPOST http://localhost:4000/testing/fixtures/users

run the test

console1

npm run testing | bunyan

console2 (JSON)

ciao test/functional/json -c test/functional/ciao.json

console3 (HTML)

ciao test/functional/html -c test/functional/ciao.json

ubuntu

In order to run nodejs on lower port without root permission the following has been installed and executed

sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep /usr/bin/nodejs
sudo setcap cap_net_bind_service=+ep  /usr/local/lib/node_modules/coffee-script/bin/coffee

In order to switch between different versions of node we installed nave which can be used easly with the following

sudo nave usemain 0.10

Start the server as a daemon:

nohup npm run supervisor >> /var/www/app.log 2>&1 &

Database

You can access collections and documents inside the database installing smog on your local machine

[sudo] npm install smog -g

and executing it

smog &

once smog is running open a browser to http://localhost:8080/ and change test to coffeestackDB inside the DSN popup

NOTE

NODE_PATH='./:$NODE_PATH' and NODE_ENV='staging' must be in ~/.bashrc or exported in the current env

Front-end

Build environment

The front-end code is using Jake as a build tool. Jake is installed by npm as one of the dev dependencies. Jake can execute tasks from Jakefile.coffee. Run jake -T to see a list of the available tasks. Run jake <task name> to execute a task. When a task depends on some other tasks, those other tasks will be executed first.

Style

CSS is compiled from Stylus code. The Stylus middleware automatically recompiles when changes are made.

Updating CoffeeScript

There is a watch Jake task that can be used to automatically compile and bundle front-end CoffeeScript when it is changed.