# express-controller-routes

> Module for connecting routes with controllers actions

Latest version **1.0.6** (published 2015-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-controller-routes
pnpm add express-controller-routes
yarn add express-controller-routes
bun add express-controller-routes
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2015-10-25 |
| First published | 2015-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | adampietrasiak |
| Maintainers | adampietrasiak |
| Keywords | express, routes, controllers, mvc |

## Links

- npm: https://www.npmjs.com/package/express-controller-routes
- npm.io page: https://npm.io/package/express-controller-routes

## Recent versions

- 1.0.6 (latest) — 2015-10-25
- 1.0.4 — 2015-10-24
- 1.0.3 — 2015-10-24
- 1.0.2 — 2015-10-24
- 1.0.1 — 2015-10-24
- 1.0.0 — 2015-10-24

## README

This module makes it easy to create routes connected with controllers actions in kind of 'rails' way

# Install

Install this module with
`npm install --save express-controller-routes`

# Useage

Firstly, create folder where all of your controller files will be. 

Name of controller file is controller name at the same time. For example file named `UserController.js` will create controller with name `user`

Inside controller file create actions this way

    // myapp/controllers/UserController.js
    exports.actionName = function(req, res) { /*your action code*/ };
    exports.anotherActionName = function(req, res) { /*your action code*/ };
    
Then in your project file (`index.js` propably) define routes this way:
    
    // myapp/index.js
    var app = express(); //express app object

    var router = require("express-controller-routes")

    router(app, "controllers", function(ctrls, get, post, put, del){
	    get("/user/:id", ctrls.user.actionName);
	    post("/user/something", ctrls.user.anotherActionName);
	    put("route...", ctrls.someController.someAction);
	    delete("route...", ctrls.someOtherController.myAction);
	    //etc...
    });
    
First argument is Express appliaction object. Second argument is folder name where you hold all your controllers files. Third argument is your function that will add routes. This function takes those parameters (order is important)
    
 - Object that will hold all your controllers with their actions
 - Function name for adding get method routes
 - Function name for adding post method routes
 - Function name for adding put method routes
 - Function name for adding delete method routes (name it different way than `delete` as it's reserved keyword

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