Skip to content

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 curre…

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? An…

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…

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, …