[add] So my next problem is that when i try adding a new dependence (npm install –save socket.io). The JSON file is also valid. I get this error: Failed to parse json So I’ve been trying to figure out why this error has been returning. All of the files (HTML,JSON,JS) are inside the same folder on my desktop. I’m using
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
How to specify a “caused by” in a JavaScript Error?
In my NodeJS program, I parse some user JSON file. So I use : The problem is that if the json file is not correctly formated, the error thrown is like: As it is not really user friendly I would like to throw an Error specifying some user friendly message (like “your config file is not well formated”) but I
Selenium WebDriver wait till element is displayed
I have searched on Google and the SO site and I get answers for JAVA but do not seem to get answers for node.js I have a web app that takes time to load. I would like the selenium program to wait till the page is loaded and then perform some actions. My current code is as follows The error
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