S
S
Svyatoslav Khusamov2016-08-05 21:24:16
Node.js
Svyatoslav Khusamov, 2016-08-05 21:24:16

Is there a module for implementing intra-program (essentially emulation) requests to an application in Express?

I made a method for req.app, with which you can make GET requests to the application, directly in the program itself without http calls. The method is simple (only GET and only json data) and does not handle errors.
Maybe there is a ready-made module that implements all possible requests to the application?

const http = require("http");
const express = require("express");

express.application.doGet = function getDataFromPath(path) {
  return new Promise((resolve, reject) => {
    let req = new http.IncomingMessage();
    req.method = "GET";
    req.url = path;
    req.headers = { accept: "application/json" };
    let res = new http.ServerResponse(req);
    res.json = resolve;
    this.handle(req, res, reject);
  });
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HoHsi, 2016-08-05
@khusamov

supertest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question