npm express cant find middleware

Issue

I have installed npm express and serve-flavicon, they are present in npm ls and npm ls --global but I’m still getting Error: Most middleware (like favicon) is no longer bundled with Express and must be installed separately

const https = require('https');
const fs = require('fs');

const express  = require('express');
const app = express();
const favicon = require('serve-favicon');

app.use(express.static('public'));
app.use(express.json());
app.use(express.favicon('public/favicon.ico'));

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options, app).listen(8000);

Solution

Try using what you imported.

app.use(favicon('public/favicon.ico'));

Answered By – Steven Spungin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published