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

@hectorjs/stub-cli

v1.47.1

Published

Command line for stub-backend library

Downloads

507

Readme

@hectorjs/stub-cli

Releases documentation

Description

The aim of this project is to mock backend services building different responses for a given authentication, cookie or request among others.

stub-cli is a command line which helps you to create new projects, generate methods and test template.

Keep it simple :smile:

Install

Install the library:

Npm

Globally (recommended):

npm install -g @hectorjs/stub-cli

or locally:

npm install @hectorjs/stub-cli --save-dev

Yarn

Globally (recommended):

yarn add -g @hectorjs/stub-cli

or locally:

yarn add @hectorjs/stub-cli --save-dev

Verification

Verify your hjs command is installed correctly.

hjs --version
hjs --help

Commands

1) hjs --help

It will display posible options available in the library.

2) hjs new/n [name-mock-service]

It creates a new project with the name provided in the brakets.

Example: hjs new mock-service

You can add the option --vs or --idea to open the IDE.

If you execute the command without project name (hjs new), the terminal will ask you for a new project (Create new project? [Yn] ). Response y when you want to create it (This is like hjs new [name-project]) or response n when you want to set in your own package.json project.

MORE INFO: hjs new --help

3) hjs generate/g [method] [name-path]

It will generate a method template resource with a test. For example , hjs g get customers/{id}/business?product={param}). More info: hjs g --help. You can generate different methods like get, head, post, delete among others.

For each method, it creates a test with dummy data. It will reduce the time to test the mock. Give it a try.

The request and response are json by default. If you want to create a scenario for xml, you have to include --xml in you cli.

You can group each resource using the --package with the name of the folder where resource will be place.

For example: hjs g g customers --package customer

NOTE: The endpoint should not start with '/' for the cli and you should escape '&' like the next example:

hjs g post customers/{id}/products?query={param1}\&identifier={identifier} MORE INFO: hjs generate --help

4) hjs test

Execute the tests which have been created by each method generate command (hjs g get ...). You can add different properties to the command as port, logs or profile.

NOTE: you can run npm run _test or yarn _test as well. MORE INFO: hjs test --help

Also you can add --logs [type] --port [port] --profile [profile]

5) hjs config [prop]

Create a config file (.hjs.config.json) where you can set the logs, port, among others settings.

hjs config --port 8090 --logs tiny --banner

The library use morgan library for the logs, so you can add different kind of logs as tiny, common...

MORE INFO: hjs config --help

6) hjs start

If you want to run the mock hjs start. Also if you want to run the mocks with nodemon listening the changes under the resources folder, execute hjs start --dev.

NOTE: you can run npm run _start or yarn _start as well. MORE INFO: hjs start --help

UI

This section is in progress at this moment.

You can run the application and navigate to http://localhost:3005/ and have a look. You need to execute the command with ui-enable option available.

Also, you can add the following option in your hjs.config.js file:

{
    "ui":{
        "enable": true
    }
}

MORE INFO: hjs start --open --ui-enable

Example

Once you create a new project, it is adding a health check endpoint by default with its test.

Let's create a project called mock-service

hjs new mock-service

We navigate to the mock-service root and execute the test:

hjs test

You will see there is already a health check endpoint by default.

If you want to run the server and test it. You need to execute the start command:

hjs start

The service will be running in the port 3005 waiting for a request.

Make a request:

curl http://localhost:3005/health

The response will be like this:

{
    "STATUS": "UP"
}

Now you can start adding new methods for your project.

Enjoy! :heart:

Respository

https://github.com/hector-js/stub-cli