javascript
Published on January 26, 2024By DeveloperBreeze
// Import required modules
const express = require('express');
const app = express();
const basicAuth = require('express-basic-auth');
// Define a user for basic authentication
const users = { 'username': 'password' };
// Use express-basic-auth middleware for authentication
app.use(basicAuth({ users }));
// Define a route accessible only to authenticated users
app.get('/secure', (req, res) => {
res.send('Authenticated route');
});
Comments
Please log in to leave a comment.