You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

http

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http

security holding package


Version published
Weekly downloads
228K
decreased by-7.24%
Maintainers
1
Install size
1.41 kB
Created
Weekly downloads
 

Package description

What is http?

The 'http' npm package is a core Node.js module that provides utilities for creating HTTP servers and clients. It allows developers to build web servers and make HTTP requests.

What are http's main functionalities?

Creating an HTTP Server

This feature allows you to create an HTTP server that listens on a specified port and hostname. The server responds with 'Hello, World!' to any incoming request.

const http = require('http');
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!');
});
server.listen(3000, '127.0.0.1', () => {
  console.log('Server running at http://127.0.0.1:3000/');
});

Making an HTTP GET Request

This feature allows you to make an HTTP GET request to a specified URL. The response data is collected and logged to the console.

const http = require('http');
http.get('http://www.example.com', (res) => {
  let data = '';
  res.on('data', (chunk) => {
    data += chunk;
  });
  res.on('end', () => {
    console.log(data);
  });
}).on('error', (e) => {
  console.error(`Got error: ${e.message}`);
});

Handling HTTP POST Requests

This feature allows you to handle HTTP POST requests. The server collects the POST data and responds with it.

const http = require('http');
const server = http.createServer((req, res) => {
  if (req.method === 'POST') {
    let body = '';
    req.on('data', chunk => {
      body += chunk.toString();
    });
    req.on('end', () => {
      res.end('Received POST data: ' + body);
    });
  } else {
    res.statusCode = 405;
    res.end('Method Not Allowed');
  }
});
server.listen(3000, '127.0.0.1', () => {
  console.log('Server running at http://127.0.0.1:3000/');
});

Other packages similar to http

Readme

Source

Security holding package

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

You may adopt this package by contacting support@npmjs.com and requesting the name.

FAQs

Package last updated on 24 Mar 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc