-1

I am in node.js. I have two files.

winston.js:

class Winston {
    constructor(count) {
        this.count = count
    }
}

start.js

const winston = require('./winston')
let myWinston = new Winston(1)

when I run the start.js,(node ./start.js)

I get an error:

ReferenceError: Winston is not defined

Any one know how I should include the Winston file?

Jeff
  • 27
  • 4
  • Try this [How to get a variable from a file to another file in node js](https://stackoverflow.com/questions/7612011/how-to-get-a-variable-from-a-file-to-another-file-in-node-js) – Andrew Halpern Sep 05 '17 at 03:10
  • First: You're instanciating Winston (Title case), and you are importing winston (lowercase). Second: you need to export the class from winston.js – Gerardo Sep 05 '17 at 03:15

2 Answers2

-1

winston.js:

You didn't export Winston class.

export.defaults = class Winston {
    constructor(count) {
        this.count = count
    }
}

start.js

You should use the result of require, not Winston.

const winston = require('./winston')
let myWinston = new winston(1)
Luan
  • 95
  • 1
  • 6
-1

Look closely for the caps W in Winston

// start.js
const Winston = require('./winston')
let myWinston = new Winston(1)

and you need to export default in the other file

// winston.js
export default class Winston {
    constructor(count) {
        this.count = count
    }
}
jperelli
  • 6,988
  • 5
  • 50
  • 85