0

Nodejs version : 4.4.7 NPM version: 2.15.8

I am running the following code, which is literally copied from the following URL

https://kafka.js.org/docs/getting-started

    const { Kafka } = require('kafkajs')

    const kafka = new Kafka({
    clientId: 'my-app',
    brokers: ['kafka1:9092', 'kafka2:9092']
    })

The above code is saved in "apps.js" file under a "simpleapp" folder. In addition to that I have installed the following


    npm install kafkajs

When I run the app.js file I get the following error

    /Users/nick/Documents/nodeprojects/simpleapp/apps.js:1
(function (exports, require, module, __filename, __dirname) { const { Kafka } = require('kafkajs')
                                                                    ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

What is the issue?

Nick
  • 157
  • 2
  • 14

1 Answers1

0

Version 4.4.7 of NodeJS is very old, and isn't even supported anymore. KafkaJS follows the same support schedule as NodeJS itself, so the oldest currently supported version is 8.

Tommy Brunn
  • 2,520
  • 2
  • 29
  • 41
  • Thanks for your response. Never expected brew to install a super old version of NodeJS. I will upgrade and run the same. Thanks – Nick Oct 04 '19 at 11:11