viliusle/miniPaint

Creating a save json api

marcpre opened this issue · 2 comments

Hello,

I am trying to create an api to save images on the backend using nodejs.

I tried the following:

const File_save_class = require('./modules/file/save.js');
const fs = require('fs');


function main() {
    var File_save = new File_save_class();

    let rawdata = fs.readFileSync('./Text-#2.json');
    let json = JSON.parse(rawdata);

    console.log("test")
    console.log(json)

}

main();

However, I get the following error:

/home/marcus/Desktop/Code/project/miniPaint/src/js/modules/file/save.js:1
import app from './../../app.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/marcus/Desktop/Code/project/projectminiPaint/src/js/saveJSONAsImageApi.js:1:25)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)

Any suggestions what I am doing wrong?

@viliusle Thank you for your reply!