Git Product home page Git Product logo

preshr's Introduction

Preshr

Yes we're irresponsibly building a Node framework

Why?

I've been writing lots of Node code recently and here's a laundry list of things I would like:

  • Designed to be deployed on bare metal servers, PaaS, and Serverless from the get go
  • Bearing that in mind, four robust abstractions for the features I write the most:
  • Request Handlers
  • Procedures - no side effects - Synchronous
  • Side Effects - deliberate API - Asynchronous
  • Response management - Rendering, returning JSON, something else?
  • Thinking about how to get some sort of in-memory and/or redis backed queue system - with multiple workers - working reliably
  • Why not try building something?

Why Preshr?

It's gonna be precious, and fresher... no

Request Handlers, Procedures, Side Effects, and Responses - anagrammed into Preshr

Roadmap

  • Likely use Fastify for Request Handlers, and Responses in early versions
  • What's a cool testing library - do people still use Mocha?
  • Probably write it in TypeScript
  • Look at Bull for the queueing system
  • Need to think about unambiguous routing
  • Utilise throng for clustering out of the box
  • ES6 transpilation? Entry points for queue processors?

API

Not sure yet, but I've got the idea of

import
  preshr,
  procedure,
  sideEffect,
  sideEffectOnQueue
} from "@preshr/core";

preshr.get("/", opts, (request, respond) => {
  const [fileSize] = procedure(() =>
    fs.appendFileSync("log.txt", JSON.stringify(request.json()))
  );

  sideEffect(() => email.send("test", "[email protected]"));

  // Add job to queue with options (job type, repeatable)
  sideEffectOnQueue('image-processing', options, () =>
    imageAndText.render("background-image.jpg", "Hello World")
  );

  // Straight forward response with object syntax
  respond({
    payload: {
      status: "Completed",
      fileSize
    },
    contentType: 'json'
    statusCode: 200
  })

});

presher.queue('image-creation', {
  // Processors are sandboxed *processes*
  // that cannot crash the worker and utilise
  // multiple cores
  processor: '/path/to/my/processor.js',
  // Global job completed on any worker for this queue
  completed: (jobId) => console.log(`${jobId} completed`)
  options: {
    // Rate limiting queues
    limiter: {
      max: 1000,
      duration: 5000
    }
  }
})

presher.queue('video-comppression', {
  // It's be great if these queue processors
  // could be greated in a folder and then
  // webpacked as entry points out, so we can
  // write ES6 everywhere, and also a centralised config
  processor: '/path/to/video/processor.js'
})

preshr.start({
  port: 3000,
  // Preshr will support clustering out of the box
  clustering: {
    workers: 4,       // Number of workers (defaults to cpu count)
    lifetime: 10000,  // ms to keep cluster alive (Infinity)
    grace: 4000,
  },
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.