How to find the latest stable npm version and upgrade npm?

In order to find the npm latest stable version, you need to visit the npm documentation web page and check the footer.

Earlier it used to mention the version number in footer but now it provides a link to the GitHub hosted repository https://github.com/npm/cli/releases/latest; so, you can directly check go to this link and check the latest stable npm version available.

Continue reading »

Should I install npm package locally or globally?

If I am beginner with npm, then this question will definitely come to my mind. To get an answer to this, you should ask the following questions to yourself:

  • How will I use the installed npm package?
  • Will I use it as a dependency in my module or will I use it as a command line tool?

 

Install locally

 

If you are going to include the package (say “slick-carousel”) using statement like “require” in node.js and then use it in your module.

npm install <package_name>

Continue reading »

How to enable the MySQL slow query log

MySQL slow query log can be to used to determine queries that take a longer time to execute in order to optimize them. The slow query log consists of SQL statements that took more than `long_query_time` seconds to execute, required at least `min_examined_row_limit` rows to be examined and fulfilled other criteria specified by the slow query log settings.

Before enabling the MySQL slow query log, we must decide criteria for SQL statements that will be logged and also select the location where they will be logged.

Continue reading »

How to fix WordPress 404 Error on saving a new post or updating a post?

I was working on a blog post and had written a part of it and saved it. After some days, I visited the post again to complete it but it would not save, clicking on “Save Draft” button displayed a 404 not found page.

I tried to edit the post with same new content multiple times but same 404 error. Then, since I already had some post content saved, I tried to save it again with no update; it worked. So, I started updating the post content in steps, it was working and content was saving.

Continue reading »

How to use cookies in JavaScript?

A Cookie is a piece of information that is stored locally on users browser and is sent with each HTTP request to the server. HTTP being a stateless protocol, cookies provide a mechanism by which we can remember user preferences and share information between web pages.

The cookies have a limit of 4KB thus when this limit is reached, you will likely be unable to create a new cookie. To make it more clear, size of all cookies under a specific domain cannot exceed 4KB.

Continue reading »

Understanding & Installing Node.js and NPM

We have been using client side/front end JavaScript to build dynamic pages where we embed the JavaScript code in HTML file, react to events and make AJAX calls for fetching data from the server.

Node.js allows you to write server side and networking applications with JavaScript.

Node.js is an open-source, cross-platform run-time environment that executes JavaScript code server-side. It is build on built on Chrome’s V8 JavaScript engine. It uses an asynchronous event-driven model and is designed for writing scalable internet applications, notably web servers.

Continue reading »

How to drop all tables in MySQL database

Once I faced a situation wherein I had no option to delete the database and was limited to use only the MySQL command line. I wasted a lot of time find and trying different ways to delete all tables in the database. So, I thought it will be worth sharing things that ultimately worked for me.

$ mysqldump -hHOSTNAME -uUSERNAME -pPASSWORD --add-drop-table --no-data DB_NAME | grep -e '^DROP \| FOREIGN_KEY_CHECKS' | mysql -hHOSTNAME -uUSERNAME -pPASSWORD DB_NAME;

Continue reading »

How to upload large files in PHP

By default PHP is configured to allow files upload of size upto 2M.

We need to adjust the following PHP configuration directives:

  1. upload_max_filesize: By default this value is 2M. We need to increase it to the maximum size of single file that we want to upload.
  2. post_max_size: It defines the maximum size of POST data that PHP will accept. This value should be greater than ‘upload_max_filesize’.
  3. memory_limit: This sets the amount of memory a PHP script is allowed to use during its execution. Set this to a value greater than ‘post_max_size’ so that PHP script can load and process the uploaded file.

Continue reading »

How to disable textarea resizing

If we add a simple textarea in a HTML form then we see that we can resize it by clicking on the bottom right corner of the textarea and dragging the mouse.

<textarea id="txt1" name="txt1" rows="5" cols="50"></textarea>

If we want to stop this resize then you have to just add a simple css as shown below.

textarea {
    resize: none;
}

Continue reading »

How to set up HTTP authentication with nginx

We will demonstrate you how to setup HTTP Authentication with Nginx on Ubuntu in this article. We are using Ubuntu 16.04.1 and have nginx version: nginx/1.10.0 installed in our machine.

“htpasswd” is used to create and update the files used to store usernames and password for basic authentication of HTTP users.

Following are the steps that we need to follow:

  1. apache2-utils
  2. Create username and password
  3. Update Nginx configuration
  4. Reload the Nginx Configuration

Continue reading »

Back to top