# ghetto

> Ghetto framework

Latest version **0.0.5** (published 2015-11-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install ghetto
pnpm add ghetto
yarn add ghetto
bun add ghetto
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2015-11-17 |
| First published | 2015-11-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Known vulnerabilities | 0 (+8 in 2 direct dependencies) |
| Install scripts | no |
| Author | mikko@aino.com |
| Maintainers | sorl |

## Links

- npm: https://www.npmjs.com/package/ghetto
- npm.io page: https://npm.io/package/ghetto

## Dependencies (9)

- [knex](https://npm.io/package/knex.md) ^0.9.0
- [path](https://npm.io/package/path.md) ^0.12.7
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [morgan](https://npm.io/package/morgan.md) ^1.6.1
- [express](https://npm.io/package/express.md) ^4.13.3
- [body-parser](https://npm.io/package/body-parser.md) ^1.14.1
- [compression](https://npm.io/package/compression.md) ^1.6.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.0
- [cookie-session](https://npm.io/package/cookie-session.md) ^1.2.0

## Recent versions

- 0.0.5 (latest) — 2015-11-17
- 0.0.4 — 2015-11-17
- 0.0.3 — 2015-11-17
- 0.0.2 — 2015-11-17
- 0.0.1 — 2015-11-17

## README

Ghetto
======
Javascript is a ghetto, we all know that. But it seems there is no way out,
the ghetto gets larger and larger every day, more and more libraries open their
doors, people from all backgrounds are moving in, even large respected
companies seem to like the ghetto now. Ok, my imagination is over for now, let's
get to the point. What is this? Why is it?

Ghetto is a framework for building websites. But there are other frameworks,
right? Yeah... so there are basically two problems that I want to solve, the
first is error handling, this is terrible in most, except for maybe Koa. If an
express.js route does not capture an error, it does not bubble up and your whole
app crashes without a proper stack trace, simply not an ideal situation. But
using ES7 async/await coroutines we can capture errors using try/catch over a
block or simply by attaching an error method to .catch. This is great news
except that it is not available yet in node, we are left with generators.
Generators can be used together with the co package for example to accomplish
this same thing, capturing errors over a block and providing a stack trace, but
the solution is just not as nice as the async/await would have been. Luckily
with the development of transpilers such as babel we can now write our code
using async/await syntax and transpile this to generators. This is how the first
problem is solved, routes in ghetto should use async/await syntax, they are also
wrapped so that a configurable error handler is called if there was an unhandled
error in that route.

The second problem with micro-frameworks like express.js is that it does not
force its users in to any particular way of organizing your code and there are
many ways to configure them badly. For new comers this is not a good thing, some
configurations are hard to get correct but there are also too many insignificant
choices that take the fun out of producing something useful. I have worked many
years with Django and there are some problems with Django for sure but getting
productive is not one of them. These decisions also pose a problem for larger
projects involving more than one developer, somebody has to make all these
decisions, which could lead to some very boring and unproductive bike shed
discussions.

A lot of things are not implemented like a default templating engine, rest
library etc.


(Pre)-installation
------------------
```
npm install -g ghetto-command
```

Create your first app using ghetto init
---------------------------------------
```
ghetto init testapp
```

Run your first app using babel-node
-----------------------------------
```
cd testapp
npm install ghetto babel-core babel-plugin-transform-async-to-generator
ghetto run
```

Navigate to [http://localhost:4100](http://localhost:4100)

Now try [http://localhost:4100/sleep](http://localhost:4100/sleep)

Oops, open up the file `router.js`. This is where the routing is configured.
Every row in the array is a route, the first position is the route path
(specified in the same way as in express.js), the second is the either first
route function (middleware) to call or a comma separated string with allowed
methods, by default only get is accepted, if you want to change allowed methods
pass something like `'get,post'`. You can append more middleware in the row
after this. Middleware are called in the order as they appear. Ok so now have a
look in `routes/demo.js` There a `require('sleep')` causing our error. Break the
application using ctrl+c and do `npm install sleep` and start the application
again:
```
./node_modules/.bin/babel-node ghetto.js
```
Try [http://localhost:4100/sleep](http://localhost:4100/sleep) a second time.

---
_Source: https://npm.io/package/ghetto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
