Category: Express

Displaying function values onto an already existing EJS template

Query asked by user I need to display a value from a JS file (indexRoutes.js) into an input box on an EJS template (calculator.ejs), I have included the script via a footer I have made. This is the code for the JS Function I have: router.post(“/calculator”, (req, res) => { let ethAddress = req.body.ethereumAddress; /*BEGINNING […]

NodeJS Mapping API data from Fetch in a JS file to an EJS Table

Query asked by user I have retrieved JSON data from Coingecko API, I wish to map it into a table on an ejs file, does anybody know how I would do so? GET for the EJS page with the API fetch inside (Located in a file called indexRoutes.js Location from root folder: routes/indexRoutes.js): router.get(“/crypto”, ensureAuthenticated,(req, […]

Share Prisma Types Between Microservices

Query asked by user I’m working on a project right now that has multiple TypeScript microservices performing operations on the same database. In each microservice, we are using the Prisma client to perform database operations. The issue I’m experiencing is we need to duplicate our schema.prisma file in each microservice and generate the Prisma client […]

How do I save data from a model.find({}) function?

Query asked by user I am trying to work out an average value for a collection in my database using Mongoose and Express. I want to use this value in the render for the “calculator” page, hence it being inside a post for the page “calculator”. However, when I do the model.find({}) function, the value […]

Mongoose schema virtual attribute always returns undefined

Query asked by user I was trying to use mongoose schema virtual functions to implement flags, But I could not make them work The mongoose database is hosted on mongodb altas. I have tried deleting the whole collection and staring again. Here is a simplified example: Let us say I have a basic User Schema: […]

npm pdfkittable ENOENT for reading file from locally in EC2

Query asked by user My Express App Ending up in the following error while running code of pdfkittable in AWS EC2, but it was working fine in my local system . Error: ENOENT: no such file or directory, open ‘./images/145.jpg’ May 17 01:51:56 ip-172-31-15-xxx my-node-server: at Object.openSync (node:fs:585:3) May 17 01:51:56 ip-172-31-15-xxx my-node-server: at Object.readFileSync […]

Making multiple Node Express API request calls

Query asked by user I followed this guide https://herewecode.io/blog/step-by-step-guide-create-first-api-with-node-express/ to create a simple Node, Express API and it all works fine, I then changed the API call to interact with SWAPI (Star Wars API). Again all works ok. But my question is if I want to make multiple calls to the SWAPI and get 2 […]

Sending array to node is taken as object using formData

Query asked by user I am performing an update where, in addition to other data, I need to send Node an array that includes the information of one or more images, but only their path and ID, not the image itself. I am performing an update where, in addition to other data, I need to […]

Express Session Not Saving

Query asked by user I know other people have run into this, but my Express session is not saving. I looked through as many questions and threads and I could but couldn’t find a fix. Please let me know what I’m doing wrong. Thanks! Here’s where it’s initialized: app.use(session({ secret: ‘BigSecret’, resave: true, cookie: { […]