Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micro

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro

Asynchronous HTTP microservices

  • 10.0.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is micro?

The 'micro' npm package is a minimalistic framework for creating HTTP microservices. It is designed to be simple, fast, and lightweight, making it ideal for building small, focused services that can be deployed independently.

What are micro's main functionalities?

Basic HTTP Server

This code demonstrates how to create a basic HTTP server using 'micro'. The server listens on port 3000 and responds with 'Hello, world!' to any incoming request.

const { send } = require('micro');
const http = require('http');

const server = http.createServer((req, res) => send(res, 200, 'Hello, world!'));

server.listen(3000, () => console.log('Server running on port 3000'));

Handling JSON Requests

This example shows how to handle JSON requests with 'micro'. The server reads the JSON body of the incoming request and responds with the same data wrapped in an object.

const { json, send } = require('micro');

module.exports = async (req, res) => {
  const data = await json(req);
  send(res, 200, { received: data });
};

Routing with micro-router

This code demonstrates how to use 'microrouter' with 'micro' to handle routing. It defines routes for GET and POST requests to '/hello' and a catch-all route for 404 Not Found responses.

const { send } = require('micro');
const { router, get, post } = require('microrouter');

const hello = (req, res) => send(res, 200, 'Hello, world!');
const notFound = (req, res) => send(res, 404, 'Not Found');

module.exports = router(
  get('/hello', hello),
  post('/hello', hello),
  get('/*', notFound)
);

Other packages similar to micro

Keywords

FAQs

Package last updated on 26 Nov 2022

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc