https://github.com/dharmendrasha/outgoing_request
NodeJs Outgoing request logger
https://github.com/dharmendrasha/outgoing_request
express http https nodejs npm npm-package outgoing package requests
Last synced: 11 months ago
JSON representation
NodeJs Outgoing request logger
- Host: GitHub
- URL: https://github.com/dharmendrasha/outgoing_request
- Owner: dharmendrasha
- Created: 2023-07-22T08:54:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-10T21:27:54.000Z (about 2 years ago)
- Last Synced: 2025-03-31T06:31:56.356Z (11 months ago)
- Topics: express, http, https, nodejs, npm, npm-package, outgoing, package, requests
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@dharmendrasha/outgoing_request
- Size: 229 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @dharmendrasha/outgoing_request
NodeJs Outgoing request logger
1. [GITHUB link](https://github.com/dharmendrasha/outgoing_request)
2. [NPM link](https://www.npmjs.com/package/@dharmendrasha/outgoing_request)
## Installation
Install this package with multiple package manager like pnpm | yarn | yarn take a look these commands
```bash
# npm
npm i @dharmendrasha/outgoing_request
# yarn
yarn install @dharmendrasha/outgoing_request
# pnpm
pnpm add @dharmendrasha/outgoing_request
```
# Usage
## CommonJS
eg.
```javascript
const { config, handler } = require('@dharmendrasha/outgoing_request')
const express = require('express')
const axios = require('axios')
const app = express()
const port = 3000
handle(
function onRequest(id, method, host, path, protocol, headers){/* callback for onRequest */},
function onResponse(id, method, rawHeaders, statusCode, statusMessage:, httpVersion){/* callback for nResponse */}
)
app.get('/', async (req, res) => {
await axios.get('https://github.com/dharmendrasha' /* any third party api can call indipendently and and request will be traced to the console and '@dharmendrasha/outgoing_request' */)
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
```
## Typescript
eg.
```typescript
//OutGoingRequestHandler.ts
import { Request, Response, NextFunction } from 'express';
import { config, handle } from '@dharmendrasha/outgoing_request';
import { logger } from './log.util';
//main.ts
import { NestFactory } from '@nestjs/core';
import type { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app/app.module';
async function bootstrap(){
const app = await NestFactory.create(AppModule, {
logger: logger,
abortOnError: isDevelopment(),
bufferLogs: isDevelopment(),
});
app.disable('x-powered-by');
handle(
(id: string, method: string, host: string | number | string[] | undefined, path: string, protocol: string, headers: OutgoingHttpHeaders) => { /** call back for on request */},
(id: string, method: string | undefined, url: string | undefined, rawHeaders: IncomingHttpHeaders, statusCode: number | undefined, statusMessage: string | undefined, httpVersion: string) => { /** call back for on response **/}
);
app.listen(port);
}
bootstrap();
```
## Contributing
Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.
Please make sure to update tests as appropriate.
## License
[MIT](https://choosealicense.com/licenses/mit/)