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

simple-fs-rest

v1.0.5

Published

A simple file-based REST service with no design, setup, or configuration required.

Downloads

2

Readme

simple-fs-rest

A simple file-based REST service with no design, setup, or configuration required

Installation

npm install simple-fs-rest --save

Summary

simple-fs-rest allows you to easily run a REST server for use with quick POC's or to immediately build a UI without designing the corresponding REST service.

It is intended to be used for local test development. It is not to be used for production or on any internet-facing server.

Usage

var express = require('express');
var simpleFsRest = require('simple-fs-rest');
var app = express();

// Link the REST Service to anything under /api. ex: /api/users/
app.use('/api',simpleFsRest());
// Link a second api path, using the ".data2" directory to hold files
app.use('/api2',simpleFsRest('.data2/'));

app.listen(8080);

Limitations

  • No security or authorization
  • No guards against malicious requests
  • Not intended for multi-user scenarios, because race conditions are not handled
  • Not a full REST implementation. Just the basics.

Implementation Details

  • Data is stored as files and directories under a ".data" directory by default. This can be customized by passing a directory name to the function.
  • Records are stored as .json files
  • All records must have a unique "id" field. If one is not specified, it will be generated and inserted into the object

Example

POST /users {"name":"Bob"}
POST /users {"name":"Matt"}
GET /users
POST /users/1/foo/bar/fizz/buzz/comments {"content":"Boo"}

All of these calls will work without any setup, and will result in files being created in the ".data" directory.

  1. A "users" directory does not exist to write to, so it is created. The passed object does not contain an "id" attribute, so one is created and inserted into the object. The "users" directory is scanned for records, and none are found, the the id:1 is used. The file ".data/users/1.json" is created containing {"id":1,"name":"Bob"}

  2. Like step #1, but since 1.json already exists, the second object gets id:2 and is written to 2.json

  3. The "users" directory is scanned for .json files, and the response is the array: [{"id":1,"name":"Bob"},{"id":2,"name":"Matt"}]. By default, it is sorted by id, but if you wanted the records returned in order of name, you could use GET /users?sort=name

  4. This is a deeply nested endpoint, and none of the directories exist. They are each created so the entire directory structure, then the JSON content is written to the file ".data/users/1/foo/bar/fizz/buzz/comments/1.json".

Supported REST Requests

GET

GET /users

Returns an Array of the contents of files in the "users" directory.

GET /users?sort=name

Sorted by the "name" field in each object

GET /users?name=Bob&age=40

Filter the returned objects and only return matches

GET /users/1

Returns the contents of "users/1.json"

POST

POST /users {"name":"Joe"}

Creates a new file in the "users" directory. Since no id is given in the object, it generates one to be the max(id) of files in the "users" directory and assigns it to the object.

POST /servers/windows/xp/ {"name":"server1"}

If a nested path is given, subdirectories will be automatically created as needed.

PUT

PUT /users/1 {"id":1,"name":"Joe"}

Update an existing resource. The object passed must be a full representation of the object, including id.

PATCH

PATCH /users/1 [ ... operations ... ]

Update an existing resource by adding, changing, removing, etc properties. A full representation of the object does not need to be given. The jsonpatch module is used to apply the patch. See that module's documentation for supported PATCH operations and syntax.

DELETE

DELETE /users/1

Delete a record. The "users/1.json" file will be removed.