I’ve got a project I’m working on that deals with managing flights and passenger numbers. I’m currently stuck implementing the function below, any suggestions for how I could go about this would be excellent, what I currently have is below which I don’t think is correct, thanks again. …
Tag: node.js
Shorten text after 50 characters but only after the current word
I need to shorten text after 50 characters but if the 50th char is at the middle of a word – cut only after the word and not before. example text: Contrary to popular belief, Lorem Ipsum is not simply text (59 chars) expected output: Contrary to popular belief, Lorem Ipsum is not simply (54 chars) I was…
How to use document.write() with a file instead of just text?
I am using socket.io to create a party game similar to cards against humanity. I am just wondering how I can keep the players name and score etc without having to send all the data to a new page when new games begin. I was thinking to just change the body of the html but stay on the same page
How to assert that function throws with a specific error message
I’m using Node v18 ( with the built-in testrunner) and the package assert/strict to test that a function call throws an error with a custom error message. I think my code should look like Unfortunately I get the following error error: ‘The “error/message” argument is ambiguous. The err…
MongoDB Problems while inserting nested data
I try to build a database for a giveaway bot using MongoDB. Once a new giveaway is created the bot runs the following code to write the new giveaway into the databank: Giveaways should be a nested document in the document with the server’s information. My schemas for this looks like this: In my Mongo At…
how to reply and send message after receive message in node js using websocket
After receive message from client, I have to connect db(mysql) and save data and need to response the result to client and inform to other(admin) client. So I need to get current socket client and special client(admin) from the socket list. Is it possible to get current socket outside of wss connection block?…
How to convert PHP MD5 in NodeJS
I couldn’t find a concrete example for my problem I need to convert this line PHP in NodeJS : I have used several things without success, like CryptoJS.HmacMD5, CryptoJS.MD5 or md5 I feel it’s a bit more complex with NodeJS, the values correspond to queries in the url that I retrieve with expres…
Babel 7.18 doesn’t transpile components outside the project root directory
I have a component sharedlib outside the babel root directory of project1. I used to use webpack to package this project without problems, but when I configured babel, I got the following error: The demo project to reproduce the problem is on github https://github.com/xybei/test_babel My project directory is …
Node JS multliple promises chaining
I have node JS api server and I’m having issues with correct chaining of the Promises: What I get in console is : 1 [Object] – all good Emppty Array Empty Array get one doc {object} – all good 1.5 {object} – all good How would I make sure when I loop over result of 1st promise my code …
how to store the value of a key for a object and pass it to the function which is a value of another key in the same object
In the above object inside dateFilter for value i am using a calculateAverage function to get the value i need to pass the same value as parameter for calculatePercentage which is a value for percentage key in the same object how to store the calculateAverage at dateFilter and pass it to calculatePercentage s…