It is pretty easy to use helmet from pure js per documentation:
const express = require('express')
const helmet = require('helmet')
const app = express()
app.use(helmet())
But how can I use it from typescript? Typings file exports a bunch of stuff, one of which is helmet interface, which cannot be called as a function.. I can import it like this, but have no idea what to do next, what should I pass to app.use?
import * as helmet from 'helmet'
I have imported the latest version of both helmet and typings:
"@types/helmet": "0.0.43",
"helmet": "^3.18.0"
terminal:
npm install helmet
npm install @types/helmet --save-dev
app.ts:
import Helmet from "helmet";
const app = express();
app.use(Helmet());
helmet middleware should be the first thing you activate once you initialized express application object. Also note the titlecase name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With