In Javascript, to include a class, constant or definition from one file to another we need to use exports. exports
and module.exports
are pointing to the same object, so sometimes you can see both styles.
class Employee { constructor(name, age, email) { this.name = name; this.age = age; this.email = email; } getStats() { return ` Name: ${this.name} Age: ${this.age} Email: ${this.email} `; } } module.exports = Employee;
var Employee = require('../models/employee'); Employee employee = new Employee('Robin hood', 1000, '[email protected]');
var Employee = require('./models/employee'); Employee employee = new Employee('Robin hood', 1000, '[email protected]');