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

polka

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polka

A micro web server so fast, it'll make you dance! :dancers:

  • 0.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
438K
decreased by-1.95%
Maintainers
1
Weekly downloads
 
Created

What is polka?

Polka is a micro web server framework for Node.js, designed to be minimal and fast. It is similar to Express but with a smaller footprint and faster performance.

What are polka's main functionalities?

Basic Routing

Polka allows you to set up basic routing with minimal code. The example demonstrates setting up a simple GET route that responds with 'Hello, world!' when accessed.

const polka = require('polka');

polka()
  .get('/', (req, res) => {
    res.end('Hello, world!');
  })
  .listen(3000, err => {
    if (err) throw err;
    console.log('> Running on localhost:3000');
  });

Middleware Support

Polka supports middleware, allowing you to execute code for every request before it reaches your route handlers. The example shows a simple logger middleware that logs the request method and URL.

const polka = require('polka');

const logger = (req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
};

polka()
  .use(logger)
  .get('/', (req, res) => {
    res.end('Hello, world!');
  })
  .listen(3000, err => {
    if (err) throw err;
    console.log('> Running on localhost:3000');
  });

Sub-routing

Polka allows you to create sub-routers for better organization of your routes. The example demonstrates setting up a sub-router for user-related routes.

const polka = require('polka');

const users = polka()
  .get('/:id', (req, res) => {
    res.end(`User: ${req.params.id}`);
  });

polka()
  .use('/users', users)
  .listen(3000, err => {
    if (err) throw err;
    console.log('> Running on localhost:3000');
  });

Other packages similar to polka

FAQs

Package last updated on 08 Feb 2019

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