Categories
JavaScript Answers

How to fix Npm Please try using this command again as root/administrator error with JavaScript?

To fix Npm Please try using this command again as root/administrator error with JavaScript, we run npm as an administrator.

To do this, we:

  1. Click Start, click All Programs, and then click Accessories.
  2. Right-click Command prompt, and then click Run as administrator.

Then we run the npm command in the administrator command prompt.

Categories
JavaScript Answers

How to install a specific version of Node on Ubuntu?

To install a specific version of Node on Ubuntu, we use the n module.

For instance, we run

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

to clear the npm cache with

sudo npm cache clean -f

Then we install the n module globally with

sudo npm install -g n

We run n with

sudo n stable

Then we install Node 16.15.1 with

sudo n 16.15.1
Categories
JavaScript Answers

How to fix Webpack 4 “size exceeds the recommended limit (244 KiB)” error with JavaScript?

To fix Webpack 4 "size exceeds the recommended limit (244 KiB)" error with JavaScript, we set devtool to false.

For instance, in webpack.config.js, we write

const mode = process.env.NODE_ENV || "development";
module.exports = {
  //...
  devtool: mode === "development" ? "inline-source-map" : false,
  mode,
  //...
};

to set devtool to false is mode isn’t 'development'.

Categories
JavaScript Answers

How to determine if object exists AWS S3 Node.JS SDK?

To determine if object exists AWS S3 Node.JS SDK, we call the headObject method.

For instance, we write

AWS.config.update({
  accessKeyId: "*****",
  secretAccessKey: "****",
  region: region,
  version: "****",
});
const s3 = new AWS.S3();

const params = {
  Bucket: s3BucketName,
  Key: "filename",
};
try {
  await s3.headObject(params).promise();
  console.log("File Found in S3");
} catch (err) {
  console.log("File not Found ERROR : " + err.code);
}

to call headObject with the params with the bucket name and key to check if the object with the key exists in the Bucket.

And we call promise to make it return a promise.

If it doesn’t throw an error, then the object is found.

Categories
JavaScript Answers

How to check if /usr/local/bin is in $PATH on Mac?

To check if /usr/local/bin is in $PATH on Mac, we print the $PATH environment variable value.

To do this, we run

echo $PATH

and check if /usr/local/bin is included in the screen output.