From 7167e06a7527c93be24c1f5e338e98a7510aa034 Mon Sep 17 00:00:00 2001 From: Gevorg Harutyunyan Date: Thu, 24 Jun 2021 16:11:53 +0400 Subject: [PATCH] Adjusted readme. --- README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b51f3f..4b05be0 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,34 @@ Via [npm](http://npmjs.org/): $ npm install http-auth ``` -## Examples +## Usage + +```javascript +// HTTP module +const http = require("http"); + +// Authentication module. +const auth = require("http-auth"); +const basic = auth.basic({ + realm: "Simon Area.", + file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass +}); + +// Creating new HTTP server. +http + .createServer( + basic.check((req, res) => { + res.end(`Welcome to private area - ${req.user}!`); + }) + ) + .listen(1337, () => { + // Log URL. + console.log("Server running at http://127.0.0.1:1337/"); + }); +``` + +Please check [examples directory](./examples) for more. -Please check [examples directory.](./examples) ## Configurations - `realm` - Authentication realm, by default it is **Users**.