U
U
UserOcheck Ochecovich2021-08-28 16:23:03
Express.js
UserOcheck Ochecovich, 2021-08-28 16:23:03

Helmet doesn't work in Node.js. Does not hide headers like X-Powered-By. What could be the problem?

I do everything according to the documentation. Swapped plugin connections before declaring routes and controllers. However, the response header in the X-Powered-By header still hangs. I use several solutions found on the Internet at once. Nothing helps. What could be the problem?

The code:

import express from 'express'
import mongoose from 'mongoose'
import fileUpload from 'express-fileupload';
import helmet from 'helmet'

// IMPORTANT IMPORTS
import postRouter from "./routes/postRouter.js";
import authRouter from "./routes/authRouter.js";

const app = express()

// UTILS
app.use(express.json())
app.use(express.static('static'))
app.use(fileUpload({}))
app.use(helmet())
app.use(helmet.hidePoweredBy())
app.disable('x-powered-by')

// ROUTES
app.use('/api', postRouter)
app.use('/auth', authRouter)


const PORT = 3000;
const DB_URL = `mongodb+srv://&w=majority`

async function startApp() {
    try {
        await mongoose.connect(DB_URL, { useUnifiedTopology: true, useNewUrlParser: true })
        app.listen(PORT, () => {
            console.log(`SERVER STARTED ON PORT ${PORT}\n===============================================================================`)
        })
    } catch (e) {
        console.log(e)
    }
}

startApp()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
karenyerevan, 2021-08-28
@karenyerevan

For 100% result use ngnix tools

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question