First you look if the client is already logged in.
If not you send a Header with Status 401 and WWW-Authenticate.
// The header you check is "Basic Username:Password".
if(req.headers.Authorization != "Basic YWRtaW46YWRtaW4=") {
//Between the "" you can write a message that should than be displayed.
res.writeHead(401, { 'WWW-Authenticate': 'Basic realm=""' });
res.end();
} else {
//If logged in
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
For people who are interested here is an example:
First you look if the client is already logged in.
If not you send a Header with Status 401 and WWW-Authenticate.
Edit:
Here is a little function.