🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

httpagent

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpagent

latest
npmnpm
Version
2.0.0
Version published
Weekly downloads
168
-8.7%
Maintainers
1
Weekly downloads
 
Created
Source

HTTP Agent

An easy to use server manager for express.js, koa and more...

How does it work

This library is a small wrapper that abstracts normal server functionality like: starting, stopping, restarting and checking status. Built on a familiar syntax from the days of /etc/init.d/nginx start|stop|restart

The HttpAgent object creates an internal pointer to the server after it's started and manages the rest of its lifecycle with easy to use helper methods. Any web framework that uses the .listen method and returns an instance of Server can be used with this service.

Getting Started

npm install --save httpagent

A basic setup might look like the following:

my-app/
  |
  |---/app.js
  |---/package.json
  |---/server.js
  |---/node_modules/
  |----------------/express/
  |----------------/httpagent/

We'll start with our application code, configured in app.js...

app.js

const express = require('express');
const HttpAgent = require('httpagent');

const app = express()

app.get('/', function (req, res) {
  res.send('Hello World');
});

module.exports = new HttpAgent(app);

Now we'll see how it's implemented in server.js...

server.js

const app = require('./app');

let server = app.start();
/**
*
* You can also do this!
* 
*/
//app.start();
//let server = app.getServer();

For the traditional server use case this above example will most likely be all you need. Lets see a couple other scenarios you might run into where this package might help.

  • Unit Testing - We've included an easy to use stop() method to make unit testing easy
  • Clear Connections - We've included a restart() method which can allow you to clear connections without having to restart the node.js process
  • Checking Server Status - Any code running the agent can query the status of the server for health checks or other purposes

The Methods

MethodArgsReturn
startport, cbServer Instance
stopcbServer Instance
restartcbServer Instance
statusnonestatus: string(OFFLINE,STOPPED,RUNNING)

FAQs

Package last updated on 12 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts