I am trying to create a module from a class but when importing it an error is generated.
C:\Program Files\nodejs\node.exe --inspect-brk=16691 applog.js Debugger listening on ws://127.0.0.1:16691/eb2bbf-a502-435d-9785-efae3b332 For help,see: https: //nodejs.org/en/docs/inspector Debugger attached.
Waiting for c:\temp\node\logs_old\applog.js:2 import Logs from ("./Modulo/logs.js"); ^^^^^^
SyntaxError: Cannot use import statement outside a module at Module._compile (internal/modules/cjs/loader.js:892:18) at Object.Module._extensions..js (internal/modules/cjs/loader.js:973: 10) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Function.Module.runMain (internal /modules/cjs/loader.js:1025:10) at internal/main/run_main_module.js:17:11 he debugger to disconnect...
logs.js class file
class Logs{
// Modulo exportado
constructor(path,name,data){
this.path = path;
this.name = name;
this.data = data;
console.log("Objeto log creado OK.");
}
getPath() {
return this.path;
}
getName() {
return this.name;
}
getData() {
return this.data;
}
setPath(newPath){
this.path = newPath;
}
setName(newName){
this.name = newName;
}
setData(newData){
this.data = newData;
}
}
export default Logs;
applog.js file
// Importar clases
import Logs from ("./Modulo/logs.js");
// Creacion de objeto
//var applogInstance = new logs();
// Pruebas de metodos
//applogInstance.write('./app.log','app.log','987654');
I have performed the following test where I can solve what you indicate.
I have modified your logs.js file to the following:
and I call it as follows:
generating the output you have defined in the constructor