Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including fastify-request-language with all npm packages installed. Try it out:

var fastifyRequestLanguage = require("fastify-request-language")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

fastify-request-language v2.0.0

A middleware to attach language to request by parsing Accept-Language header

fastify-request-language

Build Status XO code style

Adds language to the Fastify request object by parsing Accept-Language HTTP Header.

Requirements

  • Node >= 12
  • fastify >= 3

Install

npm install fastify-request-language

Usage

const fastify = require('fastify')({
    logger: true,
    trustProxy: true,
});

fastify.register(require('fastify-request-language'), {
    languages: ['en', 'hi'],
});

// Access language in request.language
fastify.get('/', (request, reply) => {
    reply.send({ language: request.language });
});

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free