# vodkakit

> Boilerplate framework for NodeJS web applications

Latest version **3.4.1** (published 2017-01-13) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

Provides the command `vodkakit`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.4.1 |
| Published | 2017-01-13 |
| First published | 2015-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Marcus Olovsson |
| Maintainers | arood |

## Links

- npm: https://www.npmjs.com/package/vodkakit
- Repository: https://github.com/arood/vodkakit
- Homepage: https://github.com/arood/vodkakit#readme
- Issues: https://github.com/arood/vodkakit/issues
- npm.io page: https://npm.io/package/vodkakit

## Dependencies (11)

- [assets](https://npm.io/package/assets.md) ^2.1.0
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [express](https://npm.io/package/express.md) ^4.14.0
- [jumanji](https://npm.io/package/jumanji.md) ^0.1.1
- [mongojs](https://npm.io/package/mongojs.md) ^2.4.0
- [inquirer](https://npm.io/package/inquirer.md) ^2.0.0
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [connect-redis](https://npm.io/package/connect-redis.md) ^3.2.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.3
- [express-busboy](https://npm.io/package/express-busboy.md) ^5.0.0
- [express-session](https://npm.io/package/express-session.md) ^1.14.2

## Recent versions

- 3.4.1 (latest) — 2017-01-13
- 3.4.0 — 2017-01-13
- 3.3.0 — 2016-08-13
- 3.2.0 — 2016-05-08
- 3.0.6 — 2015-11-29
- 3.0.5 — 2015-09-17
- 3.0.4 — 2015-05-09
- 3.0.2 — 2015-03-13
- 3.0.1 — 2015-03-13
- 3.0.0 — 2015-03-13

## README

# VodkaKit

VodkaKit is a boilerplate/template/starter kit for [Node.js](http://nodejs.org), powered by popular frameworks like [Express](http://expressjs.com). I made it after I had built a few web projects and found a file structure I liked. In the latest iteration, it also allows your to create new projects quickly with a command line tool.

<p style="text-align: center; max-width: 100%"><img src="https://cdn.rawgit.com/Arood/VodkaKit/master/vodkakit.jpg" /></p>

If you're interested in a [HAPI](http://hapijs.com) powered variant, check out [BeerKit](https://github.com/asayuki/BeerKit) made by my friend Erik.

## Features

* (M)VC-friendly file structure, with distinct division between frontend and backend code.
* Includes a boilerplate for compiling JavaScript and SASS using [Gulp](http://gulpjs.com).
* Automatic server restart when backend code changes, thanks to [Nodemon](https://github.com/remy/nodemon).
* Common settings are done automatically (like MongoDB and Redis sessions), but can be disabled if you want to add your own modifications.
* Includes a CLI-tool to quickly create new projects.

## Getting started

Make sure that you have Node.js and NPM installed. MongoDB and Redis is also recommended. Then follow one of the instructions below:

### The easy way

1.  Install VodkaKit globally (you might have to add `sudo` depending on your setup):

        npm install -g vodkakit

2.  `cd` into your project folder and type the following to get started:

        vodkakit init

3.  Install required dependencies:

        npm install

4.  Start the web server:

        npm start

    You can now access your website in your browser with the URL [localhost:1337](http://localhost:1337).

### Advanced usage

If you prefer setting up VodkaKit manually, you can simply install it by running:

    npm install --save vodkakit

Then in your startup script, add the following code:

    require('vodkakit')(function(start) {
      start();
    });

You will add your own configurations inside the function, before `start()` is called. VodkaKit expects a certain folder structure to work, read on below to find out the default values or how you can change them if you want to.

## File structure

Read this section to find out more about the file structure VodkaKit works with, and how you can override some of these paths if you wish.

Note: If you change a path, you might want to change the start script in package.json so Nodemon restarts properly when you edit your code.

### Assets

Put your static files like images here. CSS and browser JavaScript will be compiled into `styles.css` and `script.js` in this folder.

Default path: `assets/`
Override with: `this.assets` (string)

### Routes

This is where your controllers will be stored. Each controller defines the routes that will be used by Express. It doesn't matter what you name your files, but it's worth noting that they will be included in an alphabetical order, in case you need to prioritize routes.

Read further below on how to work with controllers.

Default path: `backend/routes/`
Override with: `this.routes` (string)

### Views

This is where your HTML-templates are stored. By default VodkaKit is shipped with [Jade](http://jade-lang.com), but it should work with any format supported by Express.

Default path: `frontend/views/`
Override with: `this.views` (string)

### JavaScripts

Frontend JavaScripts are stored here. If you use the optional Gulpfile, VodkaKit will compile JavaScripts in here and put the files that doesn't start with an underscore in the assets-directory.

Default path: `frontend/javascripts/`

### Stylesheets

If you use the optional Gulpfile, VodkaKit will compile SASS-files stored in this directory and put them in the assets-directory.

Default path: `frontend/stylesheets/`

## Controllers

Creating a controller is simple. They are just a CommonJS-module with a function that returns an object that contains the routes that Express will be using.

The function will be executed in the same context as the web server, so you can access Express, your database or any other property set by VodkaKit or yourself via `this`. You can also use several callbacks in an array if you want to.

Take a look at this example for more details:

    module.exports = function() {
        var db = this.db;
        return {
            "GET": {
                "/": function(req,res) {
                    res.render("index.jade");
                },
                "/cats": [
                    // You can also use an array of callbacks if you want
                    function(req,res,next) {
                        if (user) {
                            next();
                        } else {
                            res.render("error.jade");
                        }
                    },
                    function(req,res) {
                        res.render("cats.jade");
                    }
                ]
            }
        };
    };

If you want to use regular expressions on your route, pass an array like in the cats-example above but add your expression as the first object in the array.

## Reference

Availability refers to when the property or method is actually useful. `this` is shared between configuration and controllers, but some properties may not exist until after configuration, and some might still exist in your controller but changing them won't affect your application.

### this.app

This property contains ExpressJS.

Availability: configuration, preListen, controllers

### this.assets

`(string)` Path to static assets. When undefined it defaults to `assets/`

Availability: configuration

### this.busboy

VodkaKit uses [busboy](https://www.npmjs.com/package/express-busboy) to handle POST data. You can override the busboy configuration by setting this property, or set it to `null` if you want to disable it completely.

Availability: configuration

### this.db

If you choose to setup MongoDB via VodkaKit, this property will contain the MongoJS-instance.

Availability: preListen, controllers

### this.http

The [HTTP](https://nodejs.org/api/http.html#http_http_createserver_requestlistener)-server.

Availability: preListen

### this.disableCORS

By default, VodkaKit will automatically enable [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing), which enables hotlinking and such. If you want to disable this, or add your own CORS-headers, set this property to `true` so VodkaKit doesn't enable it.

Availability: configuration

### this.mongodb

`(object)` If defined, VodkaKit will setup a MongoJS-instance to `this.db`. The property should be an object with the following keys:

* `host` - Hostname to the MongoDB-server
* `collections` - An array of collection-names you want to use.

Availability: configuration

### this.preListen(callback)

`(function)` A method that runs after configuration is complete, but right before the HTTP-server starts listening to your port. You can for example use this to add a [socket.io](http://socket.io) to your server.

* `callback` - If you create a preListen-method, make sure to use the callback-function to start the server.

Availability: configuration

### this.routes

`(string)` Path to backend controllers. When undefined it defaults to `backend/routes/`

Availability: configuration

### this.session

An [express-session](https://github.com/expressjs/session) object that you can use if you want to use another session store than Redis.

Availability: configuration

### this.sessions

If you want to use Redis, enter the session configuration here.

* `redis` - Configuration for Redis
* `secret` - Session hash secret

Availability: configuration

### start()

Callback used to start the web server after configuration is complete.

Availability: configuration

## Changelog

### 3.2

- Updated a bunch of dependencies.
- Replaced `body-parser` with `express-busboy`, to enable file uploads out of the box.
- Removed Gulp from the "core" and made it an optional Gulpfile instead.
- Removed an unnecessary reference to the deprecated `sys`, which wasn't even used...

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