I have a mongoose Image Schema as below: and a Chapter schema I’ll do population for the image and I’m trying to convert the buffer to base64string for every single image in the chapter. Could anyone please help me? is there a way to do conversion on populate function in mongoose? or I have to map…
Tag: node.js
Getting error [ERR_INVALID_ARG_TYPE] while trying to login
I’ve provided login/register system to my page, but I get an error I’ve been struggling with while trying to login: Looks like something here is the problem: passwordUtils.js or passport_log.js login post route When I console.log(user) it returns But after successful register it returns And in DB:…
Calling python script with config file from node.js as a child process
I am calling a python script as a child process from node.js, the python script uses a config.ini file for some reason the python script does not call the config file when its called as a child process, but when I launch the python script ‘using python script.py’ it works, and when a replace the v…
How can I sort this array in Discord.js?
I have an array, that looks like this(size changes): The first value is the member id, the second how many messages the user has. How can I sort the array, to get the first 10 members, sorted by their messages send? The code: Answer To sort an array by numbers, you can use the .sort() method with a compare fu…
session value is not stored properly
I am using express-session and express-mysql-session in my app to generate sessions and store them in mysql database. Sessions are stored in a table called sessions. Sessions are stored in table but the value of it is not as same as the session value in client-side or console. Example: decoded value in client…
Deploying [NodeJS file written in Typescript] on Heroku
My NodeJS App is written in Typescript and I am trying to deploy it on Heroku. I was following a YouTube tutorial. My app is deployed but it’s showing me error. Can anybody tell me what’s the issue? Is it because of the app written in Typescript? I created a Procfile and added this [web: nodemon s…
How to replace switch with Object literals
When i rewriting my old code, i had a problem i don’t know to to optimize this code in past i use switch,but now i know about Object literals, my code: How i can replace him with object literals? Answer You can write the cases as object literals and iterate over them:
`throw new Error(‘Failed to load static props’)` when setting `fallback: true` in `getStaticPaths` in Next.JS
Refer to discussion here. I faced similar error. Everything worked fine when fallback is set to false. However, when fallback is set to true, next js throws error Answer After lot of searching and trial and error, I found out that the error was because of the exceptions throws inside getStaticProps. To solve …
How to Mongoose send different value on find of specific field
I have a field which contain url to an image which is protected. It needs a secret to access file and the secret expire after a time. I want that when I do Mode.find() then the url value get replaced by anther url which contains the secret. So, that I don’t have to manually every where I find from the
Create new object if it doesn’t exist, else update
I’m having quite some trouble handling objects and storing them as JSON. What I’m trying to do is next: parse json file If user1 exists, update the whole object with new data, ELSE create new object As you can probably tell, the above doesn’t work as I’d want it to. I’m used with…