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

ex-js-faker-request

v1.0.1

Published

A simple way to emulate request in ExpressJS project to get data from inner controller whitout calling rest only internal

Downloads

5

Readme

                   _             __      _                                                   _   
                  (_)           / _|    | |                                                 | |  
   _____  ________ _ ___ ______| |_ __ _| | _____ _ __ ______ _ __ ___  __ _ _   _  ___  ___| |_ 
  / _ \ \/ /______| / __|______|  _/ _` | |/ / _ \ '__|______| '__/ _ \/ _` | | | |/ _ \/ __| __|
 |  __/>  <       | \__ \      | || (_| |   <  __/ |         | | |  __/ (_| | |_| |  __/\__ \ |_ 
  \___/_/\_\      | |___/      |_| \__,_|_|\_\___|_|         |_|  \___|\__, |\__,_|\___||___/\__|
                 _/ |                                                     | |                    
                |__/                                                      |_|                      
                                                                            v1.0.0 (c) leganux.net 2007-2023 

ex-js-faker-request

A simple way to emulate request in ExpressJS project to get data from inner controller whithout calling rest http (no axios, request or http method) only internal functions

If we have a controller function made using express like this


controller.getAllusers = async function(req,res){
    
    let list = await users.find({name:req.body.name, company:req.params.company}).limit(req.query.limit).exec()
    
    res.status(200).json({
        status:200,
        data:list,
        error:'none'
        
    })
}

module.exports = controller

Commonly we use this in a route like this


let {getAllusers} = require('usercontroller.js')

router.post('/getAllusers', getAllusers)

But if we have to get the info internal is a litle complex and must of people use axios, request or another http request but is not very efficient. To solve this problem we can execute like this


//Import library
let {fakeRequestFunction, fakeResponseFunction} = require('ex-js-faker-request')

//Import controller
let {getAllusers} = require('usercontroller.js')

// create the fake req objet as json object


let main = async function (){
    
    let req = {
        body:{name:'erick'},
        params:{company:'leganux'},
        query:{limit:5},
    }

// make the instance of fake functions
    let fakeResUser = new fakeResponseFunction()
    let fakeReqUser = new fakeRequestFunction(req)
    
     await getAllusers(fakeReqUser,fakeResUser)
    
    console.log(fakeResUser.status_)
    /* console:  
    200 
    */
    console.log(fakeResUser.json_)
    /* console: 
    {
        status:200,
        data:[{},{}],
        error:'none'
    } 
    */  
}

main()