Is it possible to access cssRules in Node JS

I am attempting to modify CSS as part of a Node JS build process, but most of what I can find online refers to doing this in the DOM with Javascript. Is it possible to read a file in Node and access the equivalent of document.stylesheet or the cssRules property or is this a DOM-only… Read More Is it possible to access cssRules in Node JS

Cannot read properties of undefined (reading 'username')

hello i got this problem . And i still not find out my issue. thanks you for helping me this is code of login.js var express = require(‘express’); var router = express.Router(); var db=require(‘../database’); /* GET users listing. */ router.get(‘/login’, function(req, res, next) { res.render(‘login’); }); router.post(‘/login’, function(req, res){ var username = req.body.username; var password… Read More Cannot read properties of undefined (reading 'username')

Why the value I pass to a function behaves like a pointer?

I have this function : static calculatePrice(offer) { if (typeof (offer.TakerGets || offer.taker_gets) == "string") offer.quality = 1 / offer.quality; return offer.quality / 1000000; } I don’t understand why the function modifies the value that I pass to it (this.book[currency][side][this.j[currency][side]]). It does not modify a copy but the original as if I had passed it… Read More Why the value I pass to a function behaves like a pointer?

parseInt output wrong

console.log(parseInt("110000111010000011100101010001010101000100000000000000000001111", 2)); The output result was wrong, even it is in google browser console. The correct output is 7048259459772055567 I think the number is too big so nodejs cannot solve it? >Solution : Indeed, that number is much larger than Number.MAX_SAFE_INTEGER, so it cannot be accurately represented. You can use BigInts to work with numbers… Read More parseInt output wrong

Using promises stops variable being set

The following code sets the row.already_messaged_clients absolutely fine and is accessible outside of the loop. businesses.forEach(async function(row) { // let already_messaged_clients_arr = await getAlreadyMessagedClientsForPlaceID(row.place_id); row.already_messaged_clients = 3; }); When I use an await like this: businesses.forEach(async function(row) { let already_messaged_clients_arr = await getAlreadyMessagedClientsForPlaceID(row.place_id); row.already_messaged_clients = 3; }); row.already_messaged_clients does not get set. Why is this?… Read More Using promises stops variable being set

Display rounded number in a span in JS

A tool that I am using is displaying a room temperature on a smart mirror. This line of code is creating the temperature value: var temperatureTextWrapper = document.createTextNode( zone.state.sensorDataPoints.insideTemperature.celsius + "°" ); After this the var is just being appended to an existing span. By default, the value contains two decimal places eg. 25.76°C. However… Read More Display rounded number in a span in JS

The try/catch block fails to catch socket connection exception

I am trying to connect to a socket that DOES NOT exist for testing purposes. In such case, an exception is thrown and I expect it to be caught in the following try/catch block. createConnection is imported from the net package. try { createConnection(8000, "127.0.0.1") } catch(exception) { console.log("FAILED") } However, the try/catch fails and… Read More The try/catch block fails to catch socket connection exception

global variable in Node.js: weird behaviour

I have below couple of files of javascript: const { testFunc2 } = require("./TestFunction"); function home(val){ global.context={}; global.context.val = val; } home(3); testFunc2(); //homeFunction.js Below is TestFunction.js: exports.testFunc2=()=>{ console.log(context.val); } This code prints 3 as the output, even though I have not put global before context in testFunc2. How does this actually works? My guess… Read More global variable in Node.js: weird behaviour