Answer the question
In order to leave comments, you need to log in
How to pass array from server node js file to client simple js file with scripts?
There is a server node js file in which the database is processed and transfers all the information to the object. Like this:
index.js file
function returnOrderArray() {
var i = 0;
const promise = new Promise((resolve, reject) => {
connection.query('SELECT * FROM orders', function(error, results) {
while (i < results.length) {
order.id[i] = results[i].id;
order.wavetype[i] = results[i].wavetype;
order.color[i] = results[i].color;
order.thick[i] = results[i].thick;
order.readydate[i] = results[i].readydate;
order.createdate[i] = results[i].createdate;
order.manager[i] = results[i].manager;
i++;
}
resolve(order);
// console.log(order);
});
});
return promise;
}
app.get('/orderlist', checkUserSession, async function(request, response) {
returnOrderArray().catch(error => console.log(error)).then(() => console.log(order), module.exports.order = order,
response.render("orderlist.ejs", { username: request.session.username }));
});
var ind = require('../../index')
function asd() {
alert(ind.order);
}
Answer the question
In order to leave comments, you need to log in
I don’t know much, but it seems that through socket.io you can transfer objects to the client, and dynamically through event subscriptions from the server to the client and vice versa, and I would call the function getOrders(filter={bububu, bububu}) for example
Wait, are you exporting from a server script to a client script??? I'm afraid that won't work.
Data between the server and the client must be transferred via HTTP transport
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question