D
D
Dubolom Unicellular2020-05-12 13:22:21
Node.js
Dubolom Unicellular, 2020-05-12 13:22:21

Where to write code in nodejs server next?

I have created a nodejs server. Where to write js code next?
I have app.js:

// Подключение всех модулей к программе
const fs = require("fs");
const express = require("express");
const app = express();
const server = require("http").createServer(app);

// Отслеживание порта
server.listen(3000);

// Отслеживание url адреса и отображение нужной HTML страницы
app.get("/", function(req, res) {
  res.sendFile(__dirname + "/index.html");
});

const fileOutput = document.querySelector("#fileOutput");

fs.readFile("index.txt", "utf-8", function(err, data) {
  if (err) throw err;
  
  let fileData = data;
  fileOutput.innerText = fileOutput;
});


It gives me an error document is not definedon the command line.
And then I realized that the server cannot receive my document! How it is? I connected the server to index.html.
I tried to write everything on index.html in the script tag, but then the passage where I read the file gave me an error require is not defined

. What should I do? Where to write js code? How to use all nodejs features and modules with document?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2020-05-12
@wapster92

in html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question