Token.getInst is not a function

when I try to run the main.js file via > node main.js
it throws an error this code was taken from a good reference blog so assuming I must be wrong somewhere

Main file

//main.js

Token = require('./token')

console.log(Token)
const tokenizer = Token.getInst()
const tokens = tokenizer.tokenize('234+90')
console.log(tokens)

Token class

// token.js
const { isNum, isOp } = require('util')

class Token {
    constructor() {
        this.inst = null
        this.tokens = []
    }
    static getInst() {
        if (!this.inst)
            this.inst = new Token()
        return this.inst
    }
    
    tokenize(str) {
         //not concerned
    }
}
exports.Token = Token

Error
TypeError: Token.getInst is not a function

node version : 14.15.3

Code taken from : https://blog.bitsrc.io/parsing-expressions-in-javascript-4c156f0cbaec

14 thoughts on “Token.getInst is not a function”

Leave a Comment