npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fkc

v1.0.12

Published

FKC application service framework.

Downloads

106

Readme

Quick Start To Fkc Application Service Framework

NPM version NPM Install Size NPM Downloads NPM License

1. Install

npm install fkc

2. Create a Web

const fkc = require('fkc');
const app = fkc();
const fs = require('fs');
const options = { 
    key: fs.readFileSync('./server.key'),
    cert: fs.readFileSync('./server.crt')
};
const domain:'127.0.0.1'; // or '*.xxx.com'
const web = app.host(domain,options); 

3. Web add plug-in

web.arg('logs',(req,res)=>{
    return (d)=>{
        console.log(d);
    }
})

4. Web add middleware

web.use((ctx)=>{
    console.log('use1');
    ctx.arg.logs('Add plug-in'); 
},(ctx)=>{
    console.log('use2');
    ctx.stop();   //Enable stop
}).use((ctx)=>{
    console.log('use3');
    // ctx.res.file = './demo/my.mp4';    // Download File
    // ctx.res.static = './demo/my.mp4';  // Static File
    ctx.res.cookie = ["name=zhangsan;max-age=28800;"];     //Set cookies
    ctx.res.setHeader("Access-Control-Allow-Origin","*"); 
    ctx.res.setHeader("Access-Control-Allow-Mothods","POST,GET,DELETE,HEAD");
    ctx.res.setHeader("Access-Control-Allow-Headers","Content-Type,X-Custom-Header")
    ctx.json = 'Hello World' //Request End
})

5. Add Route /Cannot return

// Normal Mode
const opt = {
    KB:0.01,            //Data size
    err(e){             //error callback  
        console.log(e); //e:string|null
    }
}
const json = app.body.json();
const urlencoded = app.body.urlencoded(opt)
const raw = app.body.raw(opt)  //Other request bodies
const upload = app.body.upload({
    // kb:1024,         //One file size
    mb:1024,            //One file size
    // KB:1024*1024,    //Total file size    
    MB:1024*1024,       //Total file size
    dir:'./uploadDir',  //File upload directory
    err(e){             //error callback
        console.log(e);
    }
})
web.get('/upload',upload,(ctx)=>{
    console.log(ctx.req.file);     //Print File List
})
web.get('/',raw,json,urlencoded,(ctx)=>{
    ctx.msg = 'Hello';             //Assign value to "ctx.msg"
    console.log(ctx.req);          //Print Request Details
},(ctx)=>{
    console.log(ctx.msg);          //"Hello"
    console.log(ctx.req.body);     //Request body

    ctx.res.body = 'hello world!';//Response content
    // ctx.res.status = 200;       //Response status Default: 200
    // ctx.res.charset = "utf-8";  //Response charset Default: "utf-8"
    // ctx.res.type = "html";      //Response type Default: "txt"
})

//Restful Mode
web.get('/:id/:age',()=>{
    // url: /10/18?sex=1
    console.log(ctx.msg); //Hello
    console.log(ctx.req.data); //{id:xxx,age:xxx,sex:1}
})

//Reg Mode.1
web.get('/html/*/*/',()=>{
    // url: /html/xxx/xxx/
    console.log(ctx.msg); //Hello
})
//Reg Mode.2
web.get(/^\/html\/[^\\/]+\/[^\\/]+\/$/,()=>{
    // url: /html/xxx/xxx/
    console.log(ctx.msg); //Hello
})

6. File Mode

const Route = '/path';        // Add Route 
const filesDir = './file';    // File directory
// web.html(filesDir);        // Cache h5 files
// web.file(filesDir);        // Default route is'/'
// web.static(filesDir);      // Default route is'/'
web.html(Route,filesDir)      // Html  File     Route Mode: Normal     
web.file(Route,filesDir);     // Download File  Route Mode: Normal
web.static(Route,filesDir);   // Static File    Route Mode: Normal

7. File Route /Cannot return

web.get('/api','./web');      //All Method
//  file:'./web/test.js'      route: /api/test
//  file:'./web/my/test.ts'   route: /api/my/test

// test.js code
'use strict';
exports.main = async(ctx) => {
    ctx.res.body = 'hello world!';
};

8. Enable http/https service

app.http(80).https(443).cluster(3).end(()=>{
    console.log('Successfully opened');
});

// app.http(80)    //HTTP protocol port
// app.https(443)  //HTTPS protocol port
// app.cluster(3)  //Number of service clusters
// app.end()       //Function end must be used