To fix npm ERR! network getaddrinfo ENOTFOUND error with JavaScript, we fix the proxy settings.
For instance, we run
npm config set proxy http://domain:8080
to run npm config set proxy to make npm use the correct proxy URL.
To fix npm ERR! network getaddrinfo ENOTFOUND error with JavaScript, we fix the proxy settings.
For instance, we run
npm config set proxy http://domain:8080
to run npm config set proxy to make npm use the correct proxy URL.
To do array with object sorting with JavaScript Underscore sortBy, we call sortBy with the array and a callback to return the field to sort by.
For instance, we write
const sorted = _.sortBy(arr, (o) => {
return o.start.dateTime;
});
to call sortBy with arr and a callback that returns the start.dateTime property from the object to sort by this property.
An array with the sorted objects is returned.
To know if a request is http or https in Node.js, we use the req.secure property.
For instance, we write
const isSecure = req.secure;
to check if the request is secure with the req.secure property.
If it’s true, then the request is made via https.
To fix username and password not accepted when using Nodemailer, we set the auth property when we create the transporter object.
For instance, we write
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "YOUR-USERNAME",
pass: "THE-GENERATED-APP-PASSWORD",
},
});
const send = async () => {
const result = await transporter.sendMail({
from: "YOUR-USERNAME",
to: "RECEIVERS",
subject: "Hello World",
text: "Hello World",
});
console.log(JSON.stringify(result, null, 4));
};
send();
to call createTransport with an object with the auth property set to an object with the username and password.
Then we call sendMail to send the message with the from, to, subject and text fields for the email.
It returns a promise with the result of the transmission.
To fix Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 with Node, we need to add the credentials into our environment variables.
To do this, we run
$ export AWS_ACCESS_KEY_ID="your_key_id"
$ export AWS_SECRET_ACCESS_KEY="your_secret_key"
in Unix to set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
We do the same thing with
> set AWS_ACCESS_KEY_ID="your_key_id"
> set AWS_SECRET_ACCESS_KEY="your_secret_key"
on Windows.
We can also create a ~/.aws/credentials file with
[default]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>