# skafold

> Simple API route scaffolder for Express/Mongoose

Latest version **1.1.2** (published 2017-12-12) · MIT license · 0 weekly downloads

## Install

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

Provides the command `skafold`.

## 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.2 |
| Published | 2017-12-12 |
| First published | 2017-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Glenn Dimaliwat |
| Maintainers | gurenax |

## Links

- npm: https://www.npmjs.com/package/skafold
- Repository: https://github.com/Gurenax/skafold
- Homepage: https://github.com/Gurenax/skafold#readme
- Issues: https://github.com/Gurenax/skafold/issues
- npm.io page: https://npm.io/package/skafold

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [lodash-inflection](https://npm.io/package/lodash-inflection.md) ^1.5.0

## Recent versions

- 1.1.2 (latest) — 2017-12-12
- 1.1.1 — 2017-12-12
- 1.1.0 — 2017-12-06
- 1.0.9 — 2017-12-05
- 1.0.8 — 2017-12-05
- 1.0.7 — 2017-12-05
- 1.0.6 — 2017-12-05
- 1.0.5 — 2017-12-05
- 1.0.4 — 2017-12-05
- 1.0.3 — 2017-12-05
- 1.0.2 — 2017-12-05
- 1.0.1 — 2017-12-05
- 1.0.0 — 2017-12-05

## README

# Skafold [![npm version](https://badge.fury.io/js/skafold.svg)](https://badge.fury.io/js/skafold) [![npm](https://img.shields.io/npm/dt/skafold.svg)]() [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Skafold is a simple API route scaffolder for Express/Mongoose

## Installation
```
npm install -g skafold
```
or
```
yarn global add skafold
```

## Before Running Skafold
- Ensure that you have already created your model file `( e.g. models\Beer.js )`

## Running Skafold
1. Go to your project's root directory
2. Run the command 
```
skafold <Model Name> (e.g. skafold Beer)
```

## Output
After running the command, the program will generate a file `routes\beer.js` containing your generated API routes.

## Example output
```javascript
const express = require('express')
const Beer = require('../models/Beer')
const router = express.Router()

// GET - Read all beers
router.get('/beers', (req, res) => {
  Beer.find()
  .then(beers => {
    res.json(beers)
  })
  .catch(error => {
    res.status(400).json({ error: error.message })
  })
})

// GET - Read an individual beer document
router.get('/beers/:id', (req, res) => {
  const id = req.params.id
  Beer.findById(id)
  .then(beer => {
    if(beer) {
      res.json(beer)
    }
    else {
      res.status(404).json({ error: `Beer not found with id: ${id}` })
    }
  })
  .catch(error => {
    res.status(400).json({ error: error.message })
  })
})

// POST - Create a new beer document
router.post('/beers', (req, res) => {
  const attributes = req.body
  Beer.create(attributes)
  .then(beer => {
    res.status(201).json(beer)
  })
  .catch(error => {
    res.status(400).json({ error: error })
  })
})

// PATCH - Update a beer document
router.patch('/beers/:id', (req, res) => {
  const id = req.params.id
  const attributes = req.body
  Beer.findByIdAndUpdate(id, attributes, { new: true, runValidators: true })
  .then(beer => {
    if(beer) {
      res.status(200).json(beer)
    }
    else {
      res.status(404).json({ error: `Beer not found with id: ${id}` })
    }
  })
  .catch(error => {
    res.status(400).json({ error: error })
  })
})

// DELETE - Destroy a beer document
router.delete('/beers/:id', (req, res) => {
  const id = req.params.id
  Beer.findByIdAndRemove(id)
  .then(beer => {
    if(beer) {
      res.status(200).json(beer)
    }
    else {
      res.status(404).json({ error: `Beer not found with id: ${id}` })
    }
  })
  .catch(error => {
    res.status(400).json({ error: error })
  })
})

module.exports = router
```

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