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

@atinux/nuxthub

v0.2.6

Published

The Nuxt Toolkit to create full-stack applications on the Edge.

Downloads

33

Readme

NuxtHub

The Nuxt Toolkit to create full-stack applications on the Edge.

Features

  • Session management with useAuth(event)
  • Query an SQLite database with useDatabase()
  • Access key-value storage with useKV()
  • Store files with useBlob()

Blob

Upload a blob

const blob = await useBlob().put('my-file.txt', 'Hello World!', {
  contentType: 'text/plain' // optional, will be inferred from the file extension
  addRandomSuffix: true // optional, will add a suffix to the filename to avoid collisions
})
/*
{
  pathname: 'my-file-12345.txt',
  contentType: 'text/plain',
  size: 12,
  uploadedAt: '2021-08-12T15:00:00.000Z'
}
*/

Usage with file upload

export default eventHandler(async (event) => {
  const form = await readFormData(event)
  const file = form.get('file')

  return useBlob().put(file.name, file)
})

List blobs

// Get a blob object
const { blobs, cursor, hasMore } = await useBlob().list({
  limit: 10, // optional, default to 1000
  prefix: 'my-dir', // optional, will only list blobs starting with `my-dir`
})

Pagination

const blob = useBlob()
let blobs = []
let hasMore = true
let cursor

while (hasMore) {
  const result = await blob.list({
    cursor,
  })
  blobs.push(...result.blobs)
  hasMore = result.hasMore
  cursor = result.cursor
}

Get blob metadata

const blob = await useBlob().head('my-file.txt')

Delete a blob

await useBlob().delete('my-file.txt')

It returns a void response. A delete action is always successful if the blob url exists. A delete action won't throw if the blob url doesn't exists.

Serve a blob

// server/routes/[...pathname].get.ts
export default eventHandler(event => {
  const pathname = event.context.params.pathname
  return useBlob().serve(event, pathname)
})

Key-Value Storage

  • useKV() -> process.env.KV binding

  • useKV().setItem('public/')

Get a value

const value = await useKV().get('my-key')

Live demos

  • CloudFlare Pages + D1: https://nuxt-todos-edge.pages.dev
  • CloudFlare Pages + Turso: https://nuxt-todos-turso.pages.dev
  • Lagon.app + Turso: https://nuxt-todos.lagon.dev
  • Vercel Edge + Turso: https://nuxt-todos-edge.vercel.app
  • Netlify Edge + Turso: https://nuxt-todos-edge.netlify.app
  • Deno Deploy + Turso: https://nuxt-todos-edge.deno.dev

https://github.com/Atinux/nuxt-todos-edge/assets/904724/5f3bee55-dbae-4329-8057-7d0e16e92f81

Setup

Make sure to install the dependencies using pnpm:

pnpm i

Create a GitHub Oauth Application with:

  • Homepage url: http://localhost:3000
  • Callback url: http://localhost:3000/api/auth/github

Add the variables in the .env file:

NUXT_OAUTH_GITHUB_CLIENT_ID="my-github-oauth-app-id"
NUXT_OAUTH_GITHUB_CLIENT_SECRET="my-github-oauth-app-secret"

To create sealed sessions, you also need to add NUXT_SESSION_SECRET in the .env with at least 32 characters:

NUXT_SESSION_SECRET=your-super-long-secret-for-session-encryption

Development

Start the development server on http://localhost:3000

npm run dev

In the Nuxt DevTools, you can see your tables by clicking on the Drizzle Studio tab:

https://github.com/Atinux/nuxt-todos-edge/assets/904724/7ece3f10-aa6f-43d8-a941-7ca549bc208b

Deploy on CloudFlare Pages

Create a CF pages deployment linked to your GitHub repository. Make sure to select Version 2 (Beta) as the build system version.

Environment variables

NUXT_OAUTH_GITHUB_CLIENT_ID=...
NUXT_OAUTH_GITHUB_CLIENT_SECRET=...
NUXT_SESSION_PASSWORD=...

Build command

Set the build command to:

npm run build

And the output directory to dist/

D1 Database

Lastly, in the project settings -> Functions, add the binding between your D1 database and the DB variable:

d1-binding

Copy the contents from server/database/migrations/0000_heavy_xorn.sql into the D1 console to seed the database.

Turso Database

You can also use Turso database instead of CloudFlare D1 by creating a database and adding the following env variables:

TURSO_DB_URL=...
TURSO_DB_TOKEN=...

You can see a live demo using Turso on https://nuxt-todos-turso.pages.dev

License

MIT License