# mongoose-crate-localfs

> mongoose-crate StorageProvider that stores files on the local filesystem

Latest version **1.1.4** (published 2016-12-11) · 0 weekly downloads

## Install

```sh
npm install mongoose-crate-localfs
pnpm add mongoose-crate-localfs
yarn add mongoose-crate-localfs
bun add mongoose-crate-localfs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2016-12-11 |
| First published | 2014-03-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Alex Potsides |
| Maintainers | achingbrain |
| Keywords | mongoose, mongoose-crate, uploads, attachments, files |

## Links

- npm: https://www.npmjs.com/package/mongoose-crate-localfs
- Repository: https://github.com/achingbrain/mongoose-crate-localfs
- Issues: https://github.com/achingbrain/mongoose-crate-localfs/issues
- npm.io page: https://npm.io/package/mongoose-crate-localfs

## Dependencies (4)

- [mv](https://npm.io/package/mv.md) ^2.1.1
- [async](https://npm.io/package/async.md) ^2.1.4
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5
- [check-types](https://npm.io/package/check-types.md) ^7.0.0

## 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.4 (latest) — 2016-12-11
- 1.1.3 — 2016-12-11
- 1.1.2 — 2016-06-13
- 1.1.1 — 2014-08-01
- 1.1.0 — 2014-08-01
- 1.0.3 — 2014-07-14
- 1.0.2 — 2014-03-30
- 1.0.1 — 2014-03-30
- 1.0.0 — 2014-03-29

## README

# mongoose-crate-localfs

[![Dependency Status](https://david-dm.org/achingbrain/mongoose-crate-localfs.svg?theme=shields.io)](https://david-dm.org/achingbrain/mongoose-crate-localfs) [![devDependency Status](https://david-dm.org/achingbrain/mongoose-crate-localfs/dev-status.svg?theme=shields.io)](https://david-dm.org/achingbrainmongoose-crate-localfs#info=devDependencies) [![Build Status](https://img.shields.io/travis/achingbrain/mongoose-crate-localfs/master.svg)](https://travis-ci.org/achingbrain/mongoose-crate-localfs) [![Coverage Status](http://img.shields.io/coveralls/achingbrain/mongoose-crate-localfs/master.svg)](https://coveralls.io/r/achingbrain/mongoose-crate-localfs)

A StorageProvider for mongoose-crate that stores files on the local filesystem.

## Usage

```javascript
const mongoose = require('mongoose')
const crate = require('mongoose-crate')
const LocalFS = require('mongoose-crate-localfs')
const path = require('path')

const PostSchema = new mongoose.Schema({
  title: String,
  description: String
})

PostSchema.plugin(crate, {
  storage: new LocalFS({
    directory: '/path/to/storage/directory',
    path: (attachment) => `/${path.basename(attachment.path)}` // where the file is stored in the directory - defaults to this function
  }),
  fields: {
    file: {}
  }
})

const Post = mongoose.model('Post', PostSchema)
```

.. then later:

```javascript
var post = new Post()
post.attach('image', {path: '/path/to/image'}, (error) => {
  // file is now attached and post.file is populated e.g.:
  // post.file.url
})
```

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