# gridfile

> GridFile is a reusable Mongoose schema for MongoDB GridFS

Latest version **1.1.6** (published 2025-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install gridfile
pnpm add gridfile
yarn add gridfile
bun add gridfile
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2025-02-01 |
| First published | 2020-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | abskmj@gmail.com |
| Maintainers | abskmj |
| Keywords | mongoose, mongoose-schema, mongoose-model, mongodb, gridfs |

## Links

- npm: https://www.npmjs.com/package/gridfile
- Repository: https://github.com/abskmj/gridfile
- Issues: https://github.com/abskmj/gridfile/issues
- npm.io page: https://npm.io/package/gridfile

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.6 (latest) — 2025-02-01
- 1.1.5 — 2024-05-29
- 1.1.4 — 2023-03-26
- 1.1.3 — 2022-10-19
- 1.1.2 — 2022-01-14
- 1.1.1 — 2021-08-13
- 1.1.0 — 2021-05-28
- 1.0.4 — 2021-05-11
- 1.0.3 — 2021-04-01
- 1.0.2 — 2021-02-16
- 1.0.1 — 2020-09-21
- 1.0.0 — 2020-08-23

## README

![npm](https://img.shields.io/npm/v/gridfile?label=NPM) ![NPM](https://img.shields.io/npm/l/gridfile?label=License) ![npm](https://img.shields.io/npm/dt/gridfile?label=Downloads) [![Coverage Status](https://coveralls.io/repos/github/abskmj/gridfile/badge.svg?branch=master)](https://coveralls.io/github/abskmj/gridfile?branch=master) [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&color=red&logo=GitHub)](https://github.com/abskmj/gridfile)

# GridFile - Mongoose Schema for MongoDB GridFS
GridFile is a reusable [Mongoose](https://mongoosejs.com/) schema for [MongoDB GridFS](https://docs.mongodb.com/manual/core/gridfs/). No separate database setup is needed as it uses the Mongoose connection for interacting with GridFS.

# Installation
```bash
npm install gridfile
```

# Usage
- Import the schema
```javascript
const schema = require('gridfile')
```

- Create a Mongoose model from the schema
```javascript
const GridFile = mongoose.model('GridFile', schema)
```

- Upload a file
```javascript
const fileStream = fs.createReadStream('/path/to/file.ext')

const gridFile = new GridFile()
gridFile.filename = 'file.ext'
await gridFile.upload(fileStream)
```
- Download a file
```javascript
const fileStream = fs.createWriteStream('/path/to/file.ext')
const gridFile = GridFile.findById('id')

await gridFile.download(fileStream)
```

## Examples
- [Upload files to MongoDB GridFS with Express](https://abskmj.github.io/notes/posts/express/express-multer-mongoose-gridfile/) - Create express based APIs to upload and download files to and from MongoDB GridFS
- [Mongoose Query Population with GridFile Schema](https://gist.github.com/abskmj/2dafbf3296ef5dc0c7a2054110c75e53) - Store email attachments on GridFS and link them to an email to support Mongoose query population

# Documentation
Documentation is available at [API.md](API.md)

# Fixes & Improvements
Head over to the issues tab at [github.com](https://github.com/abskmj/gridfile/issues) to report a bug or suggest an improvement. Feel free to contribute to the code or documentation by creating a pull request.

# Sponsor / Support
If you find the project interesting or helpful, please consider sponsoring or supporting it at [github.com](https://github.com/abskmj/gridfile).

---
_Source: https://npm.io/package/gridfile · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
