Skip to content

Tag: node.js

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 …

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 pro…

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 Her…

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…

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/consol…