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 🙏

© 2026 – Pkg Stats / Ryan Hefner

faux-call

v0.2.7

Published

Simple mock server for your convenience and testing

Downloads

53

Readme

Faux call

Simple mock server for your convenience and testing!

Disclaimer

This is still under development, which means that the API and functionality might change.

How it works

Faux creates a VERY simple mocked database which is thrown out once the server is shut down.

Install

yarn add -D faux-call
// or
npm install --save-dev faux-call

Usage

Create a server file which will initialize Faux-call:

// ./path/to/faux.server.js

// Import Faux
const faux = require('faux-call');

// Import Models
const UserModel = require('./path/to/UserModel');

// Register API
faux.register(UserModel);

// Set API namespace
// localhost:3000/api/users
faux.config.set('api.namespace', '/api');

// Set auth namespace
// localhost:3000/auth/login
// localhost:3000/auth/logout
// localhost:3000/auth/register
faux.config.set('auth.namespace', '/auth');

// Defining custom route
faux.route.get('/my/custom/route', (res, req) => {
  return res.send('my custom response');
});

// Start faux
faux.start(3000);

Once your configuration is ready, use node to run it:

node ./path/to/faux.server.js

Accepted routes

  • GET => /route: Get all rows from database
  • POST => /route: Stores a new row on the database
  • GET => /route/:id: Gets the row with a specific id
  • PUT|PATCH => /route/:id: Updates a row with a specific id
  • DELETE => /route/:id: Deletes a row with a specific id

Attribute routes

If attributeRoutes is activated on the model, Faux will generate route attributes for you to get and patch data:

  • GET => /route/:id/:attribute: Gets a specific attribute from a row with a specific id
  • PATCH => /route/:id/:attribute: Updates a specific attribute from a row with a specific id

If you wish to ignore certain attributes (such as passwords), you can declare a protected array containing the ignored column names.

Relationship routes

If relationshipRoutes is activated on the model, Faux will generate route for you to view, add, modify and delete relationship data:

  • GET => /route/:id/relationship: Lists all related rows
  • POST => /route/:id/relationship: Adds a new row to the model
  • PATCH => /route/:id/relationship/:relationship_id: Updates a related model
  • DELETE => /route/:id/relationship/:relationship_id: Deletes a related model

Mocking the not so happy path

When testing your application, there will be times where you need to test failed states and responses. On these cases, Faux allows you to mock the status and response messages. To do so, just add a status and a JSON response string header to your request. For instance:

post('http://localhost:3000/users', data, {
    headers: {
      status: 500,
      response: '{"message": "E-mail field must be unique."}'
    }
});

Model example

// ./path/to/UserModel.js
const UserModel = {
  // Name of the model (is required)
  // String
  name: 'User',
  // Model's route base (is required)
  // String
  route: '/users',
  // Database columns (is required)
  // Array [(Column)<Strings>]
  columns: ['name', 'email', 'password'],

  /** --- OPTIONAL PROPS --- */
  // Model factory
  // Function(Faker.js) => Object {(Column): <String|Number|Bool>}
  // https://github.com/Marak/Faker.js#api-methods
  factory: faker => {
    return {
      name: faker.name.findName(),
      email: faker.internet.email(),
      password: faker.random.word(),
    };
  },
  // Number of seed to create
  // Number > 0
  seed: 50,
  // Generate attribute routes (e.g. /users/1/email)
  // Bool
  attributeRoutes: true,
  // Generate relationship routes (e.g. /users/1/profile)
  // Bool
  relationshipRoutes: true,
  // Protect attributes (dont send it nor create attribute routes)
  // Array [(Column)<Strings>]
  protected: ['password'],
  // Protect your routes with middlewares
  // Array [(middleware)<Strings>]
  middlewares: ['auth'],
  // Columns used for auth
  // Array [(Column)<Strings>]
  authenticate: ['email', 'password'],
  // Encrypted fields
  // Array [<Strings>]
  encrypt: ['password'],
  // Has one relationship with other models
  // { (Model name): column_name<String> }
  hasOne: {
    'Profile': 'user',
  },
  // Has many relationship with other models
  // { (Model name): column_name<String> }
  hasMany: {
    'Post': 'user',
  },
  // Mutate data before persisting it to the database
  // Object { (Column): <Functions> }
  mutations: {
    email: (value) => {
      // do something with the email before storing it.
    },
  }
  // Model data validation
  // Object { (Column): <Object { message: <Function>, check: <Function> }> }
  validation: {
    name: {
      message: () => 'Name is required',
      check: (value, data, databases) => {
        return !!value;
      },
    },
    email: {
      message: () => 'Invalid e-mail',
      check: (value, data, databases) => {
        const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(String(value).toLowerCase());
      }
    }
  }
};

module.exports = UserModel;

Roadmap

Functionalities and features:

Project related (documentation, website, ...):

Bugs

Version log

Author