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

json-mockify

v1.2.0

Published

A simple CRUD HTTP server for JSON files

Downloads

80

Readme

json-mockify

json-mockify is a lightweight Node.js server that serves JSON data from files, allowing for easy mocking of API responses during development and testing. It can be used as a standalone server or integrated into your existing Node.js frontend or backend projects.


Features

  • Serve JSON data from files as API responses.
  • Supports CRUD (Create, Read, Update, Delete) operations.
  • Configurable via a simple JSON configuration file.
  • Easy setup and usage.

Installation

Clone the repository:

git clone https://github.com/ritheesh4/json-mockify.git

Install dependencies:

npm install


Usage

  1. Define your JSON data files in the data directory(db.json or any file name).
  2. Configure your server settings in the config.json file.
  3. Create the mock server file(mock-server.js or any file name).
  4. Start the server:

npm start


Configuration

The config.json file allows you to customize various server settings:

  • hostname: The hostname for the server (default: "localhost").
  • port: The port number for the server (default: 3000).
  • dbFilePath: The path to the JSON data file to serve. Example config.json:

{ "port": 3000, "dbFilePath": "./db.json" }

  • Make sure that db path should be in the level of library. If you are creating a folder for this mock api, make user the db path as nested.

We have to create server.js file and need to add this configuration.

//server.js
const path = require('path');
const createServer = require('json-mockify');

// Provide the name of the custom configuration file
const customConfigFilename = 'defaultConfig.json';

// Resolve the absolute path to the custom configuration file
const customConfigPath = path.resolve(__dirname, customConfigFilename);

// Create server with custom configuration
createServer(customConfigPath);

Once the above file created, you can directly run the file using command below.

node server.js


API Endpoints

  • GET /path/to/resource: Retrieve data from the specified path.
  • POST /path/to/resource: Create a new resource.
  • DELETE /path/to/resource/: Delete a resource by ID.
  • Query based GET requests
  • Query based POST requests

Examples: To retrieve data from a JSON file named data/db.json, make a GET request to /. For example:

http://localhost:3000/


Contributing

Contributions are welcome! If you have suggestions, feature requests, or bug reports, please open an issue or create a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.