Nearsighted Paramecium Multiverse
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

damless

0.0.23 • Public • Published

DamLess

Streamify your web server.

stream.write("Hello");
stream.end("world")

DamLess has been designed to think the web as a stream.

npm install damless --save

NPM Build Status Coverage Status NPM Download Dependencies Status

Features

Structured your project using services

Dependency Injection to override default behavior

Compression & minification

0 disk access at runtime

Configuration manager

Json serializer

Security

Service.js

class Service {
};
 
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 = Service;

Dependency Injection

Inject your service and define a new http route.

Override core services to custom DamLess.

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

DamLess configuration manager

{
    "services": "./services.json",
    "http": {
        "port": 3000
    }
}

Retrieve the config object in your service.

class Service {
    constructor(config) {
        console.log(config.http.port);
    }
};

Customize the json serializer

const { Json } = require("damless");
const moment = require("moment");
const { ObjectID } = require("bson");
 
class CustomJson extends Json {
 
    constructor() {
        super();
    }
 
    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;

Override core json serializer to custom DamLess.

{
  "services": [
    { "name": "json", "location": "./services/json"}
  ]
}

Enjoy

Create a server.js

const DamLess = require("damless");
const damless = new Damless();
await damless.start();

Run server on http://localhost:3000

Use other DamLess services to develop as fast as a rocket

You want to see some examples

To run our examples, clone the Qwebs 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 Qwebs 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" .

install

npm i damless

Downloadsweekly downloads

140

version

0.0.23

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability