Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eldoy/reqlang
NodeJS HTTP server request language
https://github.com/eldoy/reqlang
Last synced: 6 days ago
JSON representation
NodeJS HTTP server request language
- Host: GitHub
- URL: https://github.com/eldoy/reqlang
- Owner: eldoy
- Created: 2022-04-20T01:09:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T01:24:15.000Z (4 months ago)
- Last Synced: 2024-10-01T23:18:28.180Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Reqlang
Set the language for NodeJS web servers.
### Install
```
npm i reqlang
```### Usage
The language of the request is looked up in this order:
1. Params lang
2. From pathname: `/en/hello`
3. From the lang cookie
4. The default language
5. Fallback to English (`en`)```js
var http = require('http')
var rekvest = require('rekvest')
var wcookie = require('wcookie')
var lang = require('reqlang')// NodeJS web server
var server = http.createServer(function(req, res) {// Add pathname to request object
rekvest(req)// Add cookie support
wcookie(req)// Set the request language
lang(req)// Set the request language, with default
lang(req, 'en')req.lang // 'en'
})
```ISC Licensed. Enjoy!
Created by [Eldøy Projects](https://eldoy.com)