Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

getting SyntaxError: Unexpected token '?' when using 'express-rate-limit'

I am trying make use of ‘express-rate-limit’ and for some reason when running the server I am getting SyntaxError: Unexpected token ‘?’ even though I am pretty sure my script does not have any syntax error.

Here is de code:

rateLimiter.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const rateLimit = require('express-rate-limit');

const rateLimiter = (limit, timeframeInMinutes) => {

    return rateLimit({
        max: limit,
        windowMs: timeframeInMinutes * 60 * 1000,
    
        message: {
            error: {
                status: 429,
                message: 'TOO_MANY_REQUESTS',
                expiry: timeframeInMinutes,
            },
        },
    
    });
};

module.exports = rateLimiter;

auth.js

const express = require('express');
const authController = require('../controllers/auth');
const rateLimiter = require('../helpers/rateLimiter');

// Router initialisation
const router = express.Router();

// Routes
router.get('/test', rateLimiter(1, 10), authController.test);

module.exports = router;

Here is a screenshot of the error:

enter image description here

>Solution :

From the documentation:

This package requires you to use Node 14 or above.

The ?? operator throwing an error indicates that you’re using an older version.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading