Down below you can see I have a nodeJS server which passes down a data object to the index page. Inside of my index.ejs file I can receive this data using <%= data %> however this only gives [object Object]. However, what I want is to receive this data inside my javascript file as an acutal object so I …
Tag: node.js
Cannot set headers after they are sent to the client bug with Express and node-postgres
I’m stuck with the issue of sending response back to the caller after retrieving something from Postgres database. It appears that headers are automatically written after fetchUserDB is executed (regardless of its success). This leads to the error ERR_HTTP_HEADERS_SENT when I try to return the response …
NodeJs Testrunner freezes / stops when setting up Express server
I’m using Node v18 with the experimental testrunner. I use express as a dev dependency for http integration tests which works fine but there is one test freezing or stopping the testrunner ( it doesn’t continue ) I’m using TS but can also reproduce it with JS, the test file HttpTests.js cont…
Encrypting data using query in Node.js and MySql
Is it safe to encrypt the data posted in MySql using query in node.js? I tried something like this and it works pretty fine in terms of encryption but I don’t know exactly how safe it is, I am pretty much a begginer in this area. Answer Let’s say I wanna encrypt the password so it could be safe fr…
JavaScript – Async/Await – How to Return result from nested functions?
I’m new to Node.js and having difficulty working with async/await model. The issue I’m having is with nested function calls returning data in an async/await method, I always get ‘undefined’. My functions structure is like this: I understand that if the top-level call is async/await the…
Import JSON inside NPM Module
I made an npm module, this module export a function that load a json file and then export the result ( a little bit simplified ) The probleme is when I import this module inside another project I have this error : I looks like when I import my module, it try to read the json inside the current directory
Prevent node.js from converting a nested object with numeric keys into array
When i have an object with a nested object within, whose keys are numbers and send it to my node.js server, then the nested object is converted to an array. How can i prevent this ? Client: Server: { new: [ ‘Test’, ‘Hello’ ] } When i add a not numeric key, everything works fine. Also w…
MongoDB attribute to array migration script
I’m trying to make a migration for a database, which has the following structure as of now: There have been some changes in how we need to handle a site, having now the possibility to have multiple sites, and not only one. So I need to change the DB to look like this: Is there a way to change the
Difficulties to make another route expressJS
I am doing a site as of my studies. The technology being free, I decided to code with nodejs/Express. For my first route /home, everything went well. But I can’t create others. Yet I thought I understood the system well. It would bother me if it was due to a silly error because I have been on this probl…
HTML content displayed as pure string instead of getting rendered as a website
Hello I am getting started with implementing APIs in my project to build a Weather reporting project.This is my .js script. Now I get the response of the post request as this is as a string but i want it yo render it like a website. Instead, when I do respond in this order the html is rendered just fine.