Why application crashes when using express-rate-limit?
I'm using express-rate-limit package version 6.0.1 to limit hits of request an I also had used express-rate-limit documentation found on https://www.npmjs.com/package/express-rate-limit
However when I use this in my app, my application crashes. I"m not understanding what is going on here. I have search allot for a conclusion but without any results. Can someone give me an idea of what I'm doing wrong???
...
//Load env vars
dotenv.config({ path: "./config/config.env" });
//Connect to database
connectDB();
const app = express();
//Set Static folder
app.use(express.static(path.join(__dirname, "public")));
// Body Parser
app.use(express.json());
// Cookie parser
app.use(cookieParser());
//Dev logging middleware
if (process.env.NODE_ENV === "development") {
app.use(morgan("dev"));
}
// File uploading
app.use(fileUpload());
// Sanitize data
app.use(mongoSanitize());
// Set security headers
app.use(helmet());
// Prevent XSS attacks
app.use(xss());
//Rate limiting
const limiter = rateLimit({
windowMs: 10 * 60 * 1000, // 10 mins
max: 1,
});
app.use(limiter);
// Prevent http param pollution
app.use(hpp());
app.use(errorHandler);
const PORT = process.env.PORT || 5000;
const server = app.listen(
PORT,
console.log(
`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`.yellow.bold
)
);
//Handle unhandled promise rejections
process.on("unhandledRejection", (err, promise) => {
console.log(`Error: ${err.message}`.red);
// Close server & exit process
server.close(() => process.exit(1));
});
Merry Christmas gurus and keep on coding!!!
from Recent Questions - Stack Overflow https://ift.tt/3szpx8d
https://ift.tt/3mY4xob
Comments
Post a Comment