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

kineticjs

v0.0.2

Published

[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Downloads

94

Readme

⚡️ KineticJS ⚡️

License

A minimalist and efficient Node.js framework for building web applications with ease. KineticJS provides a simple and flexible API for handling routes, middleware, and static files, making it ideal for developers who want to get up and running quickly without the overhead of larger frameworks.


Table of Contents


Features

  • Fast and Lightweight: Minimal overhead ensures high performance and quick response times.
  • Easy to Use: Simple APIs make building web applications straightforward and enjoyable.
  • Middleware Support: Flexible middleware system allows for powerful extensibility.
  • Routing: Supports route handling with parameters and different HTTP methods.
  • Static File Serving: Serve static files out of the box.
  • Error Handling: Centralized error handling for cleaner code.
  • Modern JavaScript: Built with modern JavaScript features using ES6+ syntax.

Installation

Install KineticJS via npm:

npm install kineticjs --save

Getting Started

Creating a Server

Create a simple server using KineticJS:

// server.js
const Kinetic = require('kineticjs');

const app = new Kinetic();

app.listen(3000, () => console.log('Server running on port 3000'));

Defining Routes

Define routes using the get, post, put, and delete methods:

// server.js
app.get('/', (req, res) => {
  res.status(200).send('Hello, World!');
});

app.post('/data', (req, res) => {
  res.status(201).json({ message: 'Data received' });
});

Using middleware

Add middleware functions to process requests:

// Body parser middleware
const { bodyParser } = require('kineticjs');

const myLogger = async (req, res, next) => {
  /* My Logger Implementation */
};

app.use(bodyParser).use(myLogger);

Error Handling

To be added

Serving Static Files

Serve static files from a directory:

const path = require('path');
app.use(Kinetic.static(path.join(__dirname, 'public')));

API Reference

Kinetic Class

Methods

  • use(middleware): Adds a middleware function.
  • use(path, router): Mounts a router on a path.
  • get(path, handler): Handles GET requests to a path.
  • post(path, handler): Handles POST requests to a path.
  • put(path, handler): Handles PUT requests to a path.
  • delete(path, handler): Handles DELETE requests to a path.
  • useError(handler): Adds an error handling middleware.
  • listen(port, callback): Starts the server on the specified port.

Router Class

Methods

  • use(middleware): Adds middleware to the router.
  • get(path, handler): Defines a GET route.
  • post(path, handler): Defines a POST route.
  • put(path, handler): Defines a PUT route.
  • delete(path, handler): Defines a DELETE route.

Middleware

Middleware functions have the signature:

function name(req, res, next) {
  /* ... */
}
  • req: The request object.
  • res: The response object.
  • next: A function to call the next middleware.

Error Handling Middleware

To be added.

Examples

Full Example

import path from 'path';
import Kinetic, { Router, bodyParser, staticFiles } from '../dist';

const app = new Kinetic();
const router = new Router();
router.get('/', (req, res) => {
  res.status(200);
  res.end('Hello from router \n');
});

router.post('/', (req, res) => {
  const { hello } = req.body;
  res.status(200);
  const message =
    hello === 'hi' ? 'Hello to you too! :D' : 'Its nice to say hello :(';
  res.end(`${message} \n`);
});

router.get('/fail', (_, res) => {
  res.status(500);
  res.end('Server Error');
});

app
  .use(bodyParser)
  .use(staticFiles(path.join(__dirname, 'public')))
  .use('/', router)
  .listen(4444, () => console.log('running'));

Accessing Static Files

Place your static files in the public directory relative to your server file:

project/
├── server.js
└── public/
    ├── index.html
    ├── css/
    │   └── styles.css
    └── js/
        └── app.js

Access them via:

  • / for index.html.
  • /css/styles.css for CSS files.
  • /js/app.js for JavaScript files.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository on GitHub.

  2. Clone your fork locally:

git clone https://github.com/your-username/kineticjs.git
  1. Create a new branch for your feature or bug fix:
git checkout -b feature-name
  1. Commit your changes with clear messages:
git commit -m "Add new feature"
  1. Push to your fork:
git push origin feature-name
  1. Create a Pull Request on the main repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

Inspired by the simplicity and flexibility of frameworks like Express.js.

Contact

For any questions or suggestions, please open an issue on GitHub or reach out via email at [email protected].