ReferenceError : window is not defined at object. Node.js

window is a browser thing that doesn’t exist on Node. If you really want to create a global, use global instead: global is Node’s identifier for the global object, like window is on browsers. But, there’s no need to create truly global variables in Node programs. Instead, just create a module global: …and since you include it in your exports, other modules can … Read more

Why am I getting “Error socket hang up” response?

I recently got this socket hang up problem. I researched for a few days until I found a solution that worked for me. So, maybe this can help. It worked for me to add the http(s)Agent property with keepAlive: true in creating the http client. Here’s an example of what it might look like: This property is responsible for managing the … Read more

Using Node.js require vs. ES6 import/export

Update Since Node v12 (April 2019), support for ES modules is enabled by default, and since Node v15 (October 2020) it’s stable (see here). Files including node modules must either end in .mjs or the nearest package.json file must contain “type”: “module”. The Node documentation has a ton more information, also about interop between CommonJS and ES modules. Performance-wise there is always the … Read more

stop all instances of node.js server

Windows Machine: Need to kill a Node.js server, and you don’t have any other Node processes running, you can tell your machine to kill all processes named node.exe. That would look like this: And if the processes still persist, you can force the processes to terminate by adding the /f flag: If you need more fine-grained control and … Read more

NodeJS – What does “socket hang up” actually mean?

I’m building a web scraper with Node and Cheerio, and for a certain website I’m getting the following error (it only happens on this one website, no others that I try to scrape. It happens at a different location every time, so sometimes it’s url x that throws the error, other times url x is fine and it’s a … Read more

The difference between “require(x)” and “import x”

This simple diagram will help you understand the difference between require and import. Apart from that, You can’t selectively load only the pieces you need with require but with import, you can selectively load only the pieces you need, which can save memory. Loading is synchronous(step by step) for require on the other hand import can be asynchronous(without waiting for previous import) so it can perform a little better … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)