Patches
os.hostname()
for Windows 7 devices using a not officially Node.js supported version
npm install hostname-patcher
For some strange reason, os.hostname()
is always broken if you're using a version of Node.js not officially supported in Windows 7 (v14.x.x and above), so, this module aims to keep it working.
News: Now also patched devices will have the real hostname, instead of the default "localhost".
You'll not have any problem using this patch, because it checks if it's needed before doing its work (see here).
To use with Common.js, just require it without even any variable assignment:
// require patch first
require('hostname-patcher');
// then os
const os = require('os');
// or module using os module
const { moduleUsingOS } = require('example');
// will output your real hostname if patch and if not
console.log(os.hostname());
To use as an ES6 module, just import it:
// import patch first
import 'hostname-patcher';
// then os
import os from 'os';
// or module using os module
import { moduleUsingOS } from 'example';
// will output your real hostname if patch and if not
console.log(os.hostname());
All examples available in the examples folder.
-
Nodemailer (Common.js example here and ES6 here)(not anymore required because the last version seems to have a fallback) -
Let us know this patch is useful for other modules
Even if single projects can use this patch individually, would be great if modules themselves start using it, because it's a lot better for users experience and more practical.
I know that this error occurs because these new Node.js versions are not anymore officially supported by Windows 7, but still today is a very usable and light OS for a lot people, so, please, keep supporting it, even if the Node.js community (but not everybody) want anymore.