Skip to content

Tag: node.js

ES6 import happening before .env import

Trying to use an environment variable from my dotenv file crashes my app because it seems the dotenv file is not loaded on time. crashes with error The API key is there, so it seems that sparkpost.js is instantiating new SparkPost() before the dotenv file gets loaded. How do I work around this? Answer Javascr…

How to run Generator Functions in Parallel?

Assuming I have a Koa web server with an endpoint like this: Now the client will get the respond after ALL the actions are performed obviously. but the things is each action is dependent on the completion of the previous. Is there a way to execute them in parallel? Note: Turning them to Promises is not an opt…

Remove empty objects from an object

I am trying to remove empty objects inside an object, here is an example with the expected output: I tried using some examples from other StackOverflow questions, however those are just for one level objects. Answer Basic function that removes empty objects First start with a function that only works with a s…

How to find the size of the file in Node.js?

I am using multer for uploading my images and documents but this time I want to restrict uploading if the size of the image is >2mb. How can I find the size of the file of the document? So far I tried as below but not working. Can anyone please help me? Answer To get a file’s size in megabytes: