0.0.0 • Published 2 years ago

expressjs-controller v0.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Install

npm i expressjs-controller

Quick start

const express = require('express')
const boot = express()
const expressjsController = require("expressjs-controller");
const path = require("path");

const port = 3000;

boot.use(expressjsController.create(path.join(__dirname, "applications")));

boot.listen(port, () => {
    console.log(`Example app listening on port ${port}`);
});

Place a file named index.js to applications/index/index/ , the structure looks like this:

boot.js
applications
--index
----index
------index.js

and the index.js content is:

class Index {
    async get(req, res) {
        res.end("Hello World");
    }
}

exports.default = Index;

The controller action pattern is /[application]/[controller]/[action],
We can visit the page via / , /index , /index/index , /index/index/index

We can also write an action with TypeScript, example here:

import IAction from "expressjs-controller/dist/interfaces/IAction";
import IRequest from "expressjs-controller/dist/interfaces/IRequest";
import IResponse from "expressjs-controller/dist/interfaces/IResponse";

export default class Index implements IAction {
    async get(req: IRequest, res: IResponse): Promise<any> {
        res.end("Hello TS");
    }
}
0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago