If you are working with WordPress version 5 and up, you might be using the REST API. I love the in-built REST API WordPress provides, especially for creating applications on top of WordPress.

The Node WPApi package makes this a breeze, especially when it comes to authentication based actions.

My first test with this package was creating a new post, and I got this error message:

Sorry, you are not allowed to create posts as this user.

I was confused at first because I entered the correct username and password for my WordPress installation. Well, as you will discover, WordPress won't just allow you to perform authentication-based requests using your standard credentials.

Once you are logged in, you need to go down to the application passwords section and generate a new password in your user profile section.

Once you enter a descriptive label, you will be presented with a randomly generated password. You will not be able to retrieve this, so copy and paste it somewhere. You will then use your currently logged in username as your username value and your newly generated application password as your password (instead of the password you use when you log in).

import WPAPI from 'wpapi';  const wp = new WPAPI({     endpoint: 'https://mycoolwebsite.com/wp-json',     username: 'user',     password: 'lcSd JKgZG w49DE TbqZ A95eM 64HJ3a' });

This is what your code would look like. I am using my generated application password but my standard username, and it works.