app.js
const http= require ('http');
const fs= require ('fs');
const path= require ('path');
const express= require ('express');
const app= express ();
const add= require ('../index.js');
fs.readdir ("../", (err, data)= >
{
console.log (data);
data.forEach (file= >
{
console.log (file + "\ t \ t" + path.extname (file) + "\ t \ t" +
fs.statSync ("../" + file) .size + "B");});
fs.writeFile ('./../Projects /new.txt', 'red', (err)= >
{
if (err) console.log (err);});});
index.js
import JSONgenerator from "./modules/generators/JSONgenerator.js";
import SVGgenerator from "./modules/generators/SVGgenerator.js";
import TXTgenerator from "./modules/generators/TXTgenerator.js";
import View from "./modules/view.js";
import Interface from "./modules/interface.js";
import Mouse from "./modules/mouse.js";
const width= window.innerWidth;
const height= window.innerHeight;
const size= width /height;
const body= document.body;
const view= new View (body, width, height, size);
const face= new Interface (body, size);
const mouse= new Mouse (view.canvas, body);
const JSONG= new JSONgenerator (view.color);
const SVGG= new SVGgenerator (body, width, height);
const TXTG= new TXTgenerator ();
window.view= view;
window.mouse= mouse;
window.face= face;
window.JSONG= JSONG;
window.SVGG= SVGG;
window.TXTG= TXTG;
Console
$ node app C: \ Users \ HP \ Documents \ NetBeansProjects \ HTMLNote \ public_html \ index.js: 1 import JSONgenerator from "./modules/generators/JSONgenerator.js";
^^^^^^ SyntaxError: Cannot use import statement outside a module at wrapSafe (internal /modules /cjs /loader.js: 984: 16)
at Module._compile (internal /modules /cjs /loader.js: 1032: 27)
at Object.Module._extensions..js (internal /modules /cjs /loader.js: 1097: 10)
at Module.load (internal /modules /cjs /loader.js: 933: 32)
at Function.Module._load (internal /modules /cjs /loader.js: 774: 14)
at Module.require (internal /modules /cjs /loader.js: 957: 19)
at require (internal /modules /cjs /helpers.js: 88: 18)
at Object. (C: \ Users \ HP \ Documents \ NetBeansProjects \ HTMLNote \ public_html \ node \ app.js: 6: 1 3) at Module._compile (internal /modules /cjs /loader.js: 1068: 30)
at Object.Module._extensions..js (internal /modules /cjs /loader.js: 1097: 10)
NodeJS version: 14.17.0
Update 0
index.js
const JSONgenerator= require ("./modules /generators /JSONgenerator.js");
const SVGgenerator= require ("./modules /generators /SVGgenerator.js");
const TXTgenerator= require ("./modules /generators /TXTgenerator.js");
const View= require ("./modules /view.js");
const Interface= require ("./modules /interface.js");
const Mouse= require ("./modules /mouse.js");
Console
export default class JSONgenerator {
^^^^^^
SyntaxError: Unexpected token 'export' at wrapSafe (internal /modules /cjs /loader.js: 984: 16)
at Module._compile (internal /modules /cjs /loader.js: 1032: 27)
at Object.Module._extensions..js (internal /modules /cjs /loader.js: 1097: 10)
at Module.load (internal /modules /cjs /loader.js: 933: 32)
at Function.Module._load (internal /modules /cjs /loader.js: 774: 14)
at Module.require (internal /modules /cjs /loader.js: 957: 19)
at require (internal /modules /cjs /helpers.js: 88: 18)
at Object. (C: \ Users \ HP \ Documents \ NetBeansProjects \ HTMLNote \ public_html \ index.js: 1:23) at Module._compile (internal /modules /cjs /loader.js: 1068: 30)
at Object.Module._extensions..js (internal /modules /cjs /loader.js: 1097: 10)
P.S Package.json unchanged.
Update 1
module.exports= class JSONgenerator {};
Console
ReferenceError: window is not defined
npm install window
Console
document is not defined
const body= window.document.body;
In the package.json file of the project add "type": "module". Change all deprecated require to import. If this is not a final application and /or can be used as a dependency, read how the export is implemented here.
Alexander Lonberg2021-12-27 08:54:49the first code listing is similar to nodejs, the second to client-side, are you confused?
nörbörnën2021-12-27 08:54:49index.js is the main file for the module, input, interface, etc., etc., app.js is the file manager and creates files (it's not ready, I'm looking for how to connect to a single system). otherwise, by calling html, but I still don't know how to pull in the rest of the "site" files.
T37082021-12-27 08:54:49- javascript : Finding the same characters in a string
- javascript : Withdrawing krakozyabr when running electron-rebuild
- javascript : How to query data with PostgreSQL in reverse order
- javascript : I want to UPDATE using placeholders in Node + MySQL
- javascript : A value different from the displayed value is UPDATEd to MySQL.
- javascript : How to partition an array from the server side
- javascript : How to run selenium webdriver on vps?
- javascript : Very long C code execution #
- javascript : Create a video conference
- javascript : How to track the addition of a new block to the page in puppeteer?
node doesn't support js modules by default. You need to replace imports with require, set up a transpiler like babel, or I think the preferred option in yours is to replace the extensions of all js-module files from .js to .mjs, which tells node that you are using es6 imports
Anynomius2021-12-27 08:54:49