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

nams

v1.0.1

Published

NAMS (New Amazing Mock Server) - A zero config mock server for node

Downloads

4

Readme

NAMS (New Amazing Mock Server)

Why

NAMS is born for help people to easily mock request with ZERO config. Can be used for developing frontend graphic stuff and don't have an active backend server or used for testing like e2e, visual regression test etc etc NAMS is based on Fastify

Install

npm i --save-dev nams

How it works

The structure of Mocks folder need to be created for simulate url path and in the final folder need to have a json or javascript index file. When NAMS reach the last folder start to search a index.json file, if not exist start to search a index.js and try to exec the function passing down this params {request, reply, folderPath} and send the output. If u want to use the fastify hook preHandler you need to create a file called prehandler.js and put it in the same folder where index.[json/js] is located.

Steps

  1. Search prehandler.js and if present exec the function with this args: (request, reply, next)
  2. Search index.json file and if present send it for answer
  3. Search index.js file and if present exec the function with this args: {request, reply, folderPath} and send the function result for answer

Session

NAMS use fastify-session and u can use it on prehandler.js file. DOC LINK

Proxy

By default NAMS give a 404 code status when it can't find a file. If u want to mock only some request you can set your custom proxy. In this case when NAMS can't find a file, use your proxy address for retrieve the answer.

Import and run

Script side

require('nams')(options)

Rember: when your node script has finished use process.exit(1/0).

Options Object

{
    port: custom NAMS port (DEFAULT: 4444),
    folderPath: path of a folder where files need to be present,
    proxy: if u want to proxy all 404 request insert here URL and automatically NAMS (if cannot find file) try to retreive API on external server
}

EXAMPLE

mocks/
|--- a/
|    |--- index.js
|--- b/
|    |--- index.json
|    |--- index.js
|--- c/
|    |--- index.json
|    |--- prehandler.js
|--- d/
     |--- e/
          |--- f/
               |--- index.json  

| Request | Response-Path | | --- | ----------- | | /a | /a/index.js | | /b | /b/index.json | | /c | /c/prehandler.js => /c/index.json | | /d/e/f | /d/e/f/index.json |

Example prehandler.js

module.exports = (request, reply, next) => {
    request.session.test = 'Insert here'
    next() 
}

Example index.js

module.exports = (request, reply, next) => {
    // DO STUFF
    return {foo: "bar"}
}