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

damless

v1.0.19

Published

Streamify your web server

Downloads

182

Readme

DamLess

DamLess help you to create a NodeJS stream api (with http chunk).

Develop your http server like a gulp script.

NPM Build Status Coverage Status NPM Download Dependencies Status

const DamLess = require("damless");
const damless = new DamLess();
damless
    .config({ http: { port: 3000 }})
    .inject("info", "./services/info")
    .inject("user", "./services/user")
    .get("/helloworld", "info", "helloworld")
    .post("/user", "user", "insertOne")
    .start();
class Info {	
    // helloworld is declare as GET:/helloworld
    helloworld(context, stream, headers) {
        stream.write("Hello");
        stream.end("world");
    }
}
const { Transform } = require("stream");
class User {	
    insertOne(context, stream, headers) {
        // Read a JSON stream request and write a response as a JSON stream.
        stream
            .pipe(new Transform({
                objectMode: true,
                transform(chunk, enc, callback) {
                    // save the chunk (user) in the database
                    callback(null, chunk);
                }
            }))
            .pipe(stream);
    }
}
npm install damless --save

Features

Dependency Injection

(context, stream, headers) like http2 interface

Services/info.js

class ServiceInfo {	
};

text(context, stream, headers) {
  stream.write("Hello");
  stream.end("world")
};

json(context, stream, headers) {
  stream.write({ name: "peter" });
  stream.end({ name: "folk" });
};

exports = module.exports = ServiceInfo;

Dependency Injection

DamLess use givemetheservice to inject all services.

You can override all damless functions or inject your new services.

It's is easier to test your api.

(context, stream, headers) -> http2 interface

DamLess has been inspired by the http2 syntax. The request and response are wrap by an unique duplex stream. This stream automatically stringify, gzip or deflate your response. It is useless to pipe a compressor.

Extend services

Use the power of ES6 to easily extends services.

const { Json } = require("damless");
const moment = require("moment");
const { ObjectID } = require("bson");

class CustomJson extends Json {

    constructor() {
        super();
    }

    // override the default onValue to deserialize mongo ObjectID
    onValue(key, value) {
        if (/\d{2}-\d{2}-\d{2}/.test(value)) return moment(value, "YYYY-MM-DD").toDate();
        if (ObjectID.isValid(value)) return new ObjectID(value);
        return super.onValue(key, value);
    }
}

exports = module.exports = CustomJson;

The default json serializer is declared in the DI as "json". Replace it to load your service.

damless
    .inject("json", "./custom-json.js")

Develop faster

Configuration manager (damless.json)

You can configure damless in javascript or via json file.

damless
    .config("./damless.json")
    .config({ http: { port: 3000 }})
    .config(config => {
        config.env = "dev"
    })
{
    "services": "./services.json",
    "http": {
        "port": 3000
    }
}

You can declare your services in an other json file.

{
    "services": [
        {
            "name": "info",
            "location": "./services/info"
        }
    ],
    "http-routes": [
        {
            "get": "/",
            "service": "info",
            "method": "text"
        }
    ]
}

Retrieve the config object in your service.

class ServiceInfo {
    // config will be injected by our DI
    constructor(config) {
        console.log(config.http.port);
    }
};

You want to see some examples

To run our examples, clone the Damless repo and install the dependencies.

$ git clone https://github.com/BenoitClaveau/damless --depth 1
$ cd damless
$ npm install
$ cd exemples/helloworld
$ node server.js

Test

To run our tests, clone the Damless repo and install the dependencies.

$ git clone https://github.com/BenoitClaveau/damless --depth 1
$ cd damless
$ npm install
$ cd tests
$ node.exe "../node_modules/mocha/bin/mocha" .