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

sudden

v1.0.12

Published

A high-level API framework built on top of express

Downloads

2

Readme

Sudden.js

Coveralls github MIT License npm version npm monthly downloads

A high-level API framework built on top of express.

This project is heavily inspired by Next.js for its simplicity and ease of use.

demo

How to use

Setup

Install it in your project:

npm install sudden

and add a script to your package.json like this:

{
  "scripts": {
    "dev": "sudden",
    "build": "sudden build",
    "start": "sudden start"
  }
}

After that, the file-system is the main API. Every .js file becomes a route that gets automatically processed.

Populate ./endpoints/index.js inside your project:

export default (req, res) => {
  res.json({
    hello: "world!"
  });
};

and then just run npm run dev and go to http://localhost:3000. To use another port, you can run npm run dev -p <your port here>.

So far, we get:

  • Automatic transpilation (with webpack and babel)
  • Automatic route reloading
  • Dynamic routes support
  • API middlewares
  • Built-in error handling
  • Built-in TypeScript support
  • Static endpoints support

Automatic transpilation

Write modern javascript right away without configuring webpack and babel.

Dynamic route support

// TODO: document this thing

Built-in middlewares

export default (req, res) => {
  const body = req.body; // The request body
  const query = req.query; // The url querystring
  const cookies = req.cookies; // The passed cookies

  res.json({
    body,
    query,
    cookies
  });
};

Custom middlewares

You can add your own middleware by extending the default router with a special file called ./endpoints/_router.js as shown below:

import cors from "cors";

export default router => {
  router.use(cors());
};

Built-in error handling

404s and execeptions are handled gracefully out of the box. Any unexpected error will return a generic 500 error to avoid leaking sensitive information. The actual error will be logged in the console.

Error handling

You can add your error handler with a special file called ./endpoints/_error.js as shown below:

export default (err, req, res) => {
  if (err.message === "some error") {
    // Do something with the error
  }
};

TypeScript

Sudden.js provides an integrated TypeScript experience out of the box.

Convert your existing endpoints from .js to .ts and restart your development server with sudden dev (normally npm run dev).

Sudden.js will guide you through installing the necessary packages to complete setup.

Static endpoints support

Static endpoints can be created by populating the ./endpoints folder with json files. The content of those json files will be sent as the response body:

{
  "ping": "pong"
}

HTTP verbs

By default, files in the ./endpoints folder will respond to any type of request. Add the HTTP verb as a suffix to your endpoint's name to allow only a specific verb like so ./endpoints/user.post.js.

The supported HTTP verbs are get, post, put, delete and patch.