'NodeJS 'Readline' is not a constructor

I'm having issues with my NodeJS app. It's supposed to be a NodeJS server to serial port, but I'm having issues with Readline and it used to throw errors about SerialPort too. If anyone can recommend how to syntax check code on node.

The error:

TypeError: readline is not a constructor
at Object.<anonymous> (/x/server.js:17:11)

The code:

const myPort = new SerialPort({
  path:portname,
  baudRate:9600,
  parser: new readline("\n")
}); 
const SerialPort = require('serialport');
const readline = require("readline");


Solution 1:[1]

I don't know what you wanted to achieve this way, but you could try:

const myPort = new SerialPort({
  path:portname,
  baudRate:9600,
  parser: readline
}); 

Now you can use readline as a myPort.parser.

If you want to know more about readline, check this out: https://www.geeksforgeeks.org/node-js-readline-module/

Solution 2:[2]

Try this with Capital letter

const SerialPort = require('serialport');
const {Readline} = require("readline");

const myPort = new SerialPort({
  path:portname,
  baudRate:9600,
  parser: new Readline("\n")
}); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashma
Solution 2 Abdelrazek Ali