I was writing a project with Nodejs, and I using the ES6. I wrote a class named Products
in Products.js
file :
class Products
{
...
}
For import this class to another file (like index.js
), I use requre('Products.js');
and this error displayed :
Error: Cannot find module 'Products.js'
How to I require this class in index.js?
I was writing a project with Nodejs, and I using the ES6. I wrote a class named Products
in Products.js
file :
class Products
{
...
}
For import this class to another file (like index.js
), I use requre('Products.js');
and this error displayed :
Error: Cannot find module 'Products.js'
How to I require this class in index.js?
Share Improve this question asked May 14, 2016 at 19:03 B. AzizanB. Azizan 932 gold badges4 silver badges13 bronze badges 1-
1
export default class HelloWorld{}
– The Reason Commented May 14, 2016 at 19:04
1 Answer
Reset to default 7You have to include the path in the require like this :
var productFile = require("./Products")
consider the .
(dot) in the require statement
Also you need to export the Products Module like
module.exports = Products