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

create-leaf

v1.0.8

Published

The Abstracted Real-Time API server framework for Backend Applications

Downloads

15

Readme

logo

An efficient server implies a lower cost of the infrastructure, a better responsiveness under load and happy users. How can you efficiently handle the resources of your server, knowing that you are serving the highest number of requests as possible, without sacrificing security validations and handy development?

Enter Leaf. Leaf is a Server-side framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture. It is inspired by Nodejs , Express , Socket.io , Mysql ,MongoDB and as far as we know, it is Realtime Server Framework

The Abstracted Realtime & REST API Server Framework

logo

leaf.js is a server container consisting of the following stacks

  • node
  • socket.io
  • express
  • mysql
  • mongodb
  • nodemon (for fast refresh , check package.json for settings).

these have been configured and abstracted in a way to make you concentrate on your API endpoints , with a clear documentaion you will be able to set up a realtime server with one of the above database (mysql, mongodb).

This branch refers to the leaf v1 release

Quick start

Create a folder and make it your current working directory:

Generate a leaf project with npx create-leaf app-name:

npx create-leaf app-name

To start the app in dev mode:

cd app-name/
npm run fast

For production mode:

cd app-name
npm run start

Under the hood npx creat-leaf app-name downloads and runs Leafjs, which in turn uses the generate functionality of Leafjs CLI.

Example - RealTime Server

everything has already been setup including express , node and socket.io all you have to do is to go to the

/api/realtime/route.js


/** REAL-TIME API
 * =======================================================================
 *  This is the router pages where all Real time APIs are 
 *  directed to 
 * =======================================================================
 */

module.exports = function (io) {
    // listerning for connection
    io.on('connection', (socket) => {
         console.log('user connected ', socket.id)  // checking for connected users 

         /**
          * Routes begins here 
          */
         require('./services/users')(socket,io) // this is a route to the users API in the ./service folder
    })
}

Inside the ./realtime/services/users.js folder


/** REAL-TIME API
 * =======================================================================
 *  This is an example to recive userdata , update it and send back 
 *  response in realtime.
 * =======================================================================
 */


// dummy user data
const userData = [
    {
        id:1,
        name:"John doe",
        gender:"male",
        age:22
    },
    {
        id:2,
        name:"kwame Agyapong",
        gender:"male",
        age:22
    },
    {
        id:3,
        name:"kofi ansah",
        gender:"male",
        age:22
    }
    
]

module.exports = userModel = (socket,io)=>{
    
      socket.on('user-data',(d)=>{
          userData.push(d) // update the data
          io.emit('get-user',userData) // send response to the listening channel 'get-user' 
      })

}

FRONTEND

On the frontend you use socket.io to listern and emit messages or data , so make sure socket.io is installed at the frontend


/** REAL-TIME API
 *  FRONT END
 */

// function to emit or send data

const SendData = ()=>{
    let data =   {
        id:7,
        name:"Ama",
        gender:"female",
        age:20
    }
    socket.emit(data,"user-data")
}

// listern for realtime response 
const useEffect(()=>{
  socket.on('get-user',(data)=>{
        console.log(data) // [...] contains the updated information in real time 
    })
},[])

Example - REST Server

/api/rest/route.js

/** REST API
 * =======================================================================
 *  This is the router pages where all APIs are 
 *  directed to 
 * =======================================================================
 */
 module.exports = function(leaf,io){

    leaf.use('/users',require('./services/users')()) // takes url with http://localhost/users/...

}

Inside the ./rest/services/users.js folder


/** API MODELS
 * =======================================================================
 *  A  file consisting of all the request needed for an API endpont 
 * 
 *  this is an example with a dummy-data of users to get userdata on 
 * 
 *  GET /http://localhost:5050/users/fetch
 * 
 *  POST /http://localhost:5050/users/add  
 * 
 *  with a listerner of 'fetch-user' for realtime comunications
 *  kindly check documentaion for more details.
 * =======================================================================
 */
const express = require('express')
const router =  new express.Router()
const {basicAuth} = require('../../../middlewares')


// dummy user data
const userData = [
    {
        id:1,
        name:"John doe",
        gender:"male",
        age:22
    },
    {
        id:2,
        name:"kwame Agyapong",
        gender:"male",
        age:22
    },
    {
        id:3,
        name:"kofi ansah",
        gender:"male",
        age:22
    }
    
]

module.exports = function userEndpoint() {
    
    // fetch user endpoint
    router.get('/fetch',basicAuth,async(req,res,next)=>{
       res.status(200).send(userData)
    })

    // add user data and get realtime response on listerning to 'fetch-user'
    router.post('/add',basicAuth,async (req,res,next)=>{
          let data = {
            id:34,
            name:req.body.name,
            gender:req.body.gender,
            age:req.body.age
          }
          userData.push(data)
          res.status(200).json({message:userData})
         
    })

return router; // make sure you return router
}

for the frontend for this server you can use the fetch method in javascript or any other http method for sending and recieving API's

Do you want to know more? Head to the Getting Started.

Leafjs v1.x

Note

This framework is intended for people who knows the below stacks

  • Nodejs
  • Express
  • Socket.io
  • MongoDb
  • Mysql

Core features

  • Highly Scalable: Leaf was build with scalability as the first to consider
  • Extendible: Leaf is fully extensible via other plugins and ability to add more database to it
  • Developer friendly: the framework is built to be very expressive and help the developer in their daily use, without sacrificing performance and security.

Ecosystem

  • Community - Community supported plugins.
  • Live Examples - Multirepo with a broad set of real working examples.
  • Discord - Join our discord server and chat with the maintainers.

Support

Please visit Leafjs help to view prior support issues and to ask new support questions.

Team

Leafjs is the result of the work of a great community. Team members of the soma engineering team (A delivery app intended t make campus life easy).

Lead Maintainers:

Leafjs Core team

Acknowledgements

This project is kindly sponsored by:

License

Licensed under MIT.