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

gridfs-extra

v1.0.2

Published

A simple wrapper for the MongoDB GridFSBucket-API

Downloads

1

Readme

gridfs-extra

GitHub package.json dynamicnpm type definitions

Top LanguageCode SizeNPM Bundle SizeLicense

npm dev dependency versionnpm dev dependency versionnpm dev dependency versionDependencies

Goto CounterGithub DownloadsGitHub issuesGithub pull requestsGitHub last commit

NPM DownloadsGitHub package.json version (subfolder of monorepo)

A simple wrapper for the MongoDB GridFSBucket-API. If you need a similar wrapper for mongoose GridFSBucket-API, see mongoose-gridfs-extra

This package is designed to avoid operations on the stream objects provided by the native API, thereby saving time.

Install

install npm package

npm install gridfs-extra

or clone from Github

# ssh
git clone [email protected]:peachest/gridfs-extra.git

# http
git clone https://github.com/peachest/gridfs-extra.git

Usage

Complete runnable example is provided. See example/example.{cjs,mjs}.

After cloning the repository to local, run:

cd gridfs-extra
node example/example.cjs
node example/example.mjs

Import

// ESModule
import * as gridfs from "gridfs-extra"
import mongodb from "mongodb"

// or CommandJS
const mongodb = require('mongodb')
const gridfs = require("gridfs-extra")

Connect to Mongodb Server

const client = new mongodb.MongoClient("mongodb://localhost:27017");

await client.connect()
// or top-level await is not allowed
client.connect().then(async () => {
    // put the following code here
})

Create GridFS bucket

const db = client.db('test')
const bucketName = "testBucket";
const options = {
    bucketName
}

// gridfs-extra
const bucket = gridfs.createGridFSBucket(db, options)
// or mongodb native API
const bucket = new mongodb.GridFSBucket(db, options) ;

Write file into bucket

// Read Buffer type file content
const fileName = ""
let file = await fs.readFile("")

// Write file into bucket
const gridFSFile = await gridfs.writeFileByName(bucket, file, fileName)
const id = gridFSFile._id

Read file from bucket

// Read file from bucket
file = await gridfs.readFileById(bucket, id)
// or use fileName
file = await gridfs.readFileByName(bucket, fileName, {
    revision: -1 // default value
})

:warning: A bucket can store files with the same name. If you wonder how the bucket will retrun when read file by name, see the following native doc from mongodb gridfs bucket:

If there are multiple files with the same name, this will stream the most recent file with the given name (as determined by the uploadDate field). You can set the revision option to change this behavior.

As for the revision:

The revision number relative to the oldest file with the given filename.

  • 0 gets you the oldest file,
  • 1 gets you the 2nd oldest,
  • -1 gets you the newest.

License

Apache 2.0