Registry / storage / multer-gridfs-storage

multer-gridfs-storage

JSON →
library5.0.2jsnpmunverified

A Multer storage engine for uploading files directly to MongoDB's GridFS. Version 5.0.2 requires Node >=12, peer dependency on multer ^1.4.2. Supports both URL-based and existing database connections, connection caching, Mongoose compatibility, and TypeScript types. Key differentiator: automatic connection management and file buffering while connecting. Maintained but with limited recent activity; last release 2021.

npm install multer-gridfs-storage
INSTALL
IMPORT
SIG · MULTER-GRIDFS-STOR
M
multer-gridfs-storage
storagejavascriptv5.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GridFsStorage
import { GridFsStorage } from 'multer-gridfs-storage'
const GridFsStorage = require('multer-gridfs-storage')
Named export. CommonJS users must destructure: const { GridFsStorage } = require('multer-gridfs-storage')
GridFsStorage
const { GridFsStorage } = require('multer-gridfs-storage')
const GridFsStorage = require('multer-gridfs-storage').GridFsStorage
CommonJS: destructure from module exports; do not access .GridFsStorage property
default export
import GridFsStorage from 'multer-gridfs-storage'
import { GridFsStorage } from 'multer-gridfs-storage'
Module also provides a default export that is a function (not class). Named export is preferred.
Types
import type { GridFsStorageOptions } from 'multer-gridfs-storage'
TypeScript types are bundled; import for configuration types.

Shows how to set up an Express server with multer and GridFS storage, including environment variable for MongoDB URL.

import express from 'express'; import multer from 'multer'; import { GridFsStorage } from 'multer-gridfs-storage'; const url = process.env.MONGO_URL ?? 'mongodb://localhost:27017/mydb'; const storage = new GridFsStorage({ url }); const upload = multer({ storage }); const app = express(); app.post('/upload', upload.single('file'), (req, res) => { res.json({ file: req.file }); }); app.listen(3000);
Debug
Known issues
breakingVersion 5.x dropped support for callback-based configuration; all config must be Promise or sync.
fix
Use async/await or return a Promise from configuration function.
affects: >=5.0.0
deprecatedThe `db` option (passing a ready MongoClient) is deprecated in favor of `url` and `options`.
fix
Use `url` connection string instead of passing `db` directly.
affects: >=5.0.0
gotchaGridFsStorage constructor can throw synchronously if connection fails; wrap in try-catch.
fix
Wrap in try-catch: try { new GridFsStorage({ url }) } catch (e) { ... }
affects: >=4.0.0
breakingRemoved support for Node <12. Old versions may not work with newer MongoDB drivers.
fix
Upgrade Node to >=12 or use version 4.x.
affects: >=5.0.0
Errors
Common errors & fixes
Cannot find module 'multer-gridfs-storage'
Package not installed or missing in dependencies.
fix
Run: npm install multer-gridfs-storage
TypeError: GridFsStorage is not a constructor
Incorrect import: using default import when module exports a named export.
fix
Use: const { GridFsStorage } = require('multer-gridfs-storage');
MongoError: Authentication failed
Missing or incorrect credentials in connection string or options.
fix
Ensure url includes username:password or use options: { auth: { user, password } }
GridFsStorage requires a url or db option
Neither 'url' nor 'db' provided in configuration object.
fix
Provide a valid MongoDB connection string in 'url' option.
Upgrade
Version history
5.0.2latest on npm
Audit
Dependencies
multerrequiredPeer dependency; required to use as storage engine
Agent activity
30 hits · last 30 days
node
28
Amazon
1
Resources
multer-gridfs-storage — npm install multer-gridfs-storage · libregistry