1.0.1 • Published 6 years ago

ksp-express v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

ksp-express

npm version npm bundle size (minified) license

Create a express web site with ksp framework

This package need ksp framework. You can find him by clicking here

Install

$ npm install ksp ksp-express

Usage

const ksp = require('ksp')
const kspExpress = require('ksp-express')

ksp.use(kspExpress())
ksp.runKsp('express init')

ksp.runKsp('express route get', '/', (req, res) => {
    ksp.runKsp('express send', 'Hello world!', res) // or res.send('Hello world!')
})

ksp.runKsp('express listen', 3000, (port) => console.log('Server listen on ' + port))

More example can be found here (eg. router/middleware/404)

Ksp Methods

express init (?callback: () => void)

Init the express app

ksp.runKsp('express init')
express use (fn: function)

Allow you to use middleware or 404 page

ksp.runKsp('express use', bodyParser.json())
express set (key: any, value: any)

Allow you to set your key to express

ksp.runKsp('express set', 'view engine', 'pug')
express core get (): express.App

Get the express app

var app = ksp.runKsp('express core get')
express core set (app: express.App)

Set the express app

var app = ...
ksp.runKsp('express core set', app)
express route (get/post/put) (url: string, run: function)

Create a get/post/put route

ksp.runKsp('express route get', '/', (req, res) => {
    res.send('Hello world!')
})
express router create (url: string)

Create a router

ksp.runKsp('express router create', '/user', (router) => {
    // todo
})
express router (get/post/put) (url: string, run: function, router: express.Router)

Create a get/post/put route to the router

ksp.runKsp('express router get', '/login', (req, res) => {
    res.render('login', {})
}, router)
express send (response: any, res: express.Response)

Send a response to a route

ksp.runKsp('express send', 'Hello world!', res)
express send with status (response: any, status: number, res: express.Response)

Send a response with a status to a route

ksp.runKsp('express send with status', '404 not found', 404, res)
express render (view: string, data: any, res: express.Response)

Render a view to a route

ksp.runKsp('express render', 'setting', {
    user: userData
}, res)
express redirect (url: string, res: express.Response)

Redirect to an url

ksp.runKsp('express redirect', '/user/login', res)
express listen (port: number, ?callback: (?port: numbre) => void)

Listen the express app

ksp.runKsp('express listen', 3000, (port) => console.log('Server listen on ' + port))

Contribution

You can fork the repository, improve or fix it and then send the pull requests back if you want to see them here. I really appreciate that. ❤

License

MIT License

Copyright (c) 2019 dotjov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.