Skip to content
Advertisement

Tag: node.js

Difference between microtask and macrotask within an event loop context

I’ve just finished reading the Promises/A+ specification and stumbled upon the terms microtask and macrotask: see http://promisesaplus.com/#notes I’ve never heard of these terms before, and now I’m curious what the difference could be? I’ve already tried to find some information on the web, but all I’ve found is this post from the w3.org Archives (which does not explain the difference

Node.JS readFileSync() function

index.js server.js router.js index.html I’m trying to store the file path in a variable and then feed it ti readFileSync() function, but this gives me fllowing error in the console. but if I enter the path “D:/nodejs/file_upload/view/index.html” in the function directly then it shows me the page in the browser. I stored the index.html file in the view folder Answer

Use window.crypto in nodejs code

I am trying to use the window.crypto.getRandomValues method in a nodejs script. From my understanding there is no window element when I run a simple code like this in node: Which is why I get this error: How can I use this method in my code? Thanks Answer You can use the built-in crypto module instead. It provides both a

How to get list of days in a month with Moment.js

Using Moment.js I would like to get all days in a month of specific year in an array. For example: any suggestions? I looked through Moment.js docs but couldn’t find anything. The closet I got was this: But this only return an int with total days for specific month not an array with each day. Answer Here’s a function that

How to load external js script from URL in Node.js

I have a node.js server running on a VPS and I want to use a js script that is served from another server, something like: How do I load this script and use it in my node.js file? Thanks! Answer exec(‘wget http://example.com/api/js’, function(stdout) { }); should do the trick. If you need advanced control, use http module.

Node.js console.log vs console.info

What is the benefit of using console.log vs console.info? Or any of the other console commands for that matter? vs I thought it might change the color of the output or concatenate some sort of label, but they seem to all do the same thing. And according to the documentation here: https://nodejs.org/api/console.html#console_console_info_data they seem to all do the same as

Why couldn’t popular JavaScript runtimes handle synchronous-looking asynchronous script?

As cowboy says down in the comments here, we all want to “write [non-blocking JavaScript] asynchronous code in a style similar to this: ” So people have come up solutions to this problem like callback libraries (eg async) promises event patterns streamline domains and generators. But none of these lead to code as simple and easy to understand as the

Advertisement