Why is there error GET net::ERR_ABORTED 404 (Not Found)?

Error test1.ru/:19 GET test1.ru:96/build.js net::ERR_ABORTED 404 (Not Found)
index.html
<!DOCTYPE html>
<html>
the <head>
<meta charset="utf-8" />
<title>the System</title>
<link rel="stylesheet" href="style.css">
<script type="text/javascript"></script>
</head>

the <body>
<div class="header">
<div class="header__section">
<div class="header__item headerButton1"><a href="#">Portfolio</a></div>
<div class="header__item headerButton2"><a href="#">Rating</a></div>
</div>
</div>
<input type="button" name="b" value="Login" />
<script src="build.js"></script>
</body>
</html>


test.js
var mysql = require('mysql');

console.log('Get connection ...');

var conn = mysql.createConnection({
database: 'university',
host: "localhost",
user: "aaa",
password: "aaa"
});


conn.connect();
var query = conn.query("SELECT `fio` FROM `students` WHERE `id`=1",function(error,result){
if (error) throw error;
console.log(result);
});

used browserfy
the folder contains files:
node_modules
bundle.js
index.html
package.json
package-lock.json
style.css
test.js
April 7th 20 at 15:33
1 answer
April 7th 20 at 15:35
Solution
You connect some build.js instead test.js/bundle.js
It's not my care(
Now there is another error:
Uncaught TypeError: Net.createConnection is not a function
at Connection.connect (bundle.js:20241)
at Object.223.mysql (bundle.js:36736)
at o (bundle.js:1)
at r (the bundle.js:1)
at bundle.js:1
- Adelbert.Huel commented on April 7th 20 at 15:38
@jeanne_Eichma, I immediately noticed that you have the file you want to start using node on the client is ahah, remove a file attachment from an html page and run in the console NODE:
> node test.js
- Maeve_Doyle51 commented on April 7th 20 at 15:41
I need the data in the browser output - Adelbert.Huel commented on April 7th 20 at 15:44
@jeanne_Eichma, so send data from the server to the client, but it's better to throw a request to a server and receive data on the client.

Client:

async function getData(url) {

 url instanceof String && url.length ? url : '/';

 const options = {
 method: 'POST',
 headers: {
 'Content-Type' : 'application/json'
}
};

 let response = await fetch(url, options);

 let data = response.json();

 return data;

}

const data = getData(); // Your data

console.log(data);


Server:

var mysql = require('mysql');

console.log('Get connection ...');

var conn = mysql.createConnection({
database: 'university',
host: "localhost",
user: "aaa",
password: "aaa"
});


conn.connect();

app.post('/', (req, res) => {
 conn.query("SELECT `fio` FROM `students` WHERE `id`=1",function(error,result){
 if (error) throw error;
 Res. send(result.map(item => item));
});
});


It is a ready solution, but it will not work without the express setup. You left to go in the documentation to integrate express and run the application. To at least have learned something. - Maeve_Doyle51 commented on April 7th 20 at 15:47
@Dasia.Nader, thanks for the help and sorry for another question, please
index.html
<!DOCTYPE html>
<html>
the <head>
 <meta charset="utf-8" />
</head>
the <body>
 <script src="client.js"></script>
</body>
</html>


client.js
async function getData(url) {
 url instanceof String && url.length ? url : '/'; 
 const options = {
 method: 'POST',
 headers: {
 'Content-Type' : 'application/json'
}
};

 let response = await fetch(url,options);
 let data = response.json(); 
 return data; 
}

 const data = getData('http://test1.ru:96/'); //?
 console.log(data);


server.js
const express = require('express');
const mysql = require('mysql');

const app = express();

console.log('Get connection ...');

var conn = mysql.createConnection({
database: 'university',
host: "localhost",
user: "aaa",
password: "aaa"
});


conn.connect();

app.post('/', (req, res) => {
 conn.query("SELECT `fio` FROM `students` WHERE `id`=1",function(error,result){
 if (error) throw error;
 Res. send(result.map(item => item));
});
});

app.listen(96);


and the error is Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
5e4c1678c92b3261983037.png - Adelbert.Huel commented on April 7th 20 at 15:50
@jeanne_Eichma,
1.
url instanceof String && url.length ? url : '/'; // Examine

getData() // standard is '/' don't need to enter the url


2. Error in the promis is likely due to the fact that the data is not received, try to deduce in the console the result on the server, then we will know for sure. - Maeve_Doyle51 commented on April 7th 20 at 15:53
@Dasia.Nader,
1. an error occurs
5e4cc22dc5d51404124110.png
2. the connection is established, data obtained
5e4cc24957b55456811204.png - Adelbert.Huel commented on April 7th 20 at 15:56
@jeanne_Eichma, add await before a response.json - Maeve_Doyle51 commented on April 7th 20 at 15:59
@jeanne_Eichma, and you have an obvious mistake in the query, you have not cleaned the filter string of the url? - Maeve_Doyle51 commented on April 7th 20 at 16:02
@Dasia.Nader,
error message
5e4cd6f5e6eb5436174503.png

no, nothing has changed
client.js
async function getData(url) {
 url instanceof String && url.length ? url : '/';

 const options = {
 method: 'POST',
 headers: {
 'Content-Type' : 'application/json'
}
};

 let response = await fetch(url, options);
 let data = await response.json();
 return data;

}

const data = getData(); 
console.log(data);


server.js
const express = require('express');
const mysql = require('mysql');

const app = express();

console.log('Get connection ...');

var conn = mysql.createConnection({
database: 'university',
host: "localhost",
user: "aaa",
password: "aaa"
});

conn.connect();

app.post('/', (req, res) => {
 conn.query("SELECT `fio` FROM `students` WHERE `id`=1",function(error,result){
 if (error) throw error;
 console.log(result); 
 Res. send(result.map(item => item));
});
});

app.listen(96);
- Adelbert.Huel commented on April 7th 20 at 16:05
@jeanne_Eichma, print to the console the url, print to the console all that can be derived, debugging guide - Maeve_Doyle51 commented on April 7th 20 at 16:08
@Dasia.Nader,
ReferenceError: url is not defined
5e4cfdfaaedef867750040.png

conclusion through
app.post('/', (req, res) => {
 conn.query("SELECT `fio` FROM `students` WHERE `id`=1",function(error,result){
 if (error) throw error;
 Res. send(result.map(item => item));
});
});

does nothing, but
var query = conn.query("SELECT `fio` FROM `students` WHERE `id`=1",function(error,result){
if (error) throw error;
console.log(result);
});

the data obtained
in processing customer faults stored
5e4cff1f4b4c8757356924.png

if you look only at the server, swears on express
5e4cff82bf3f8879168813.png

using browserify
5e4cffdcc98fc677383948.png - Adelbert.Huel commented on April 7th 20 at 16:11
Yes, not on the server Url..........

I kind of figured out where I went wrong, that it should work:

async function getData(url) {

let queryForUrl = url instanceof String && url.length ? url : '/';

 const options = {
 method: 'POST',
 headers: {
 'Content-Type' : 'application/json'
}
};

 let response = await fetch(queryForUrl, options);
 let data = await response.json();
 return data;

}

const data = getData(); 
console.log(data);
- Maeve_Doyle51 commented on April 7th 20 at 16:14
@Dasia.Nader,
anyway
5e4d3de9c4c7c504698281.png

and still the same error
5e4d3e07beb2b306621802.png - Adelbert.Huel commented on April 7th 20 at 16:17
@jeanne_Eichma, corrected - Maeve_Doyle51 commented on April 7th 20 at 16:20
@Dasia.Nader,
5e4d46f6c7828375201053.png
5e4d4701cb7c5061772508.png - Adelbert.Huel commented on April 7th 20 at 16:23
I can't help if you fill in the host and will throw a link to a website, then you can - Maeve_Doyle51 commented on April 7th 20 at 16:26

Find more questions by tags JavaScriptMySQLNode.js