Skip to content
Advertisement

Tag: node.js

toUpperCaseFunction does not work with await keyword

I was trying to use an if clause like this: I got an error: TypeError: database.getValue(…).toUpperCase is not a function However when I change the above if clause to It works fine. Why does this happen in Nodejs? Answer Property access (.) has higher operator precedence (20) than await (17). Your current code is equivalent to: because the .s get

How to properly add admin user to a database?

Let’s say I have an endpoint for posting new users with a logic like this: This would work but now of course every user could set the isAdmin flag. Another way would be adding admin users manually to the database but this is probably not the best way. Is there a recommended way to solve this problem? Answer You can

Javascript can’t replace string

_.replace() doesn’t replacing anything in string. I tried like 5 different ways to do it but still nothing and I guess you are my last hope. My code: I want to get rid of <br /> Output: Answer You need to pass a regular expression with global flag to replace all occurrence of a pattern.

Change content of JSON using NodeJS

I want to edit my JSON file using NodeJS, everything work exept the last write, my JSON file get } at the end. My code : packs.json : modules.json : Result of modules.json : Answer Your disableAllModules and activateModules functions return before their respective readFile callback functions are evaluated. As a result, when you do this: The following happens: disableAllModules()

Unable to connect to socket – Vanilla JS to node.js

I am trying to work with socket.io, however I am unable to establish a connection between my client (Vanilla HTML/JS) and my server (node.js). Server code: I also have several endpoints and functions that are exposed in the same file, though they didn’t seem relevant (as far as I know), so I didn’t include them here, but can if needed.

extract private key from .pem file

I want my code to extract private key from my pem file . My pem file looks like this -> —–BEGIN RSA PRIVATE KEY—– some encrypted code —–END RSA PRIVATE KEY—– . I have the same code in ruby but i’m not able to do this in javascript. Answer Keep in mind, this will only work if there is one

Advertisement