I Created a CLI to Cross-Post Your Articles On Dev, Hashnode, and Medium
Tags: showdev, writing, tooling, javascript
Published: 2021-03-26 21:46:22

_This article was originally published on [my personal blog](https://blog.shahednasser.com/)_

If you own a blog like me, but also cross-post your articles on platforms like Dev, Hashnode, and Medium, it gets tedious to post your articles in different places.

So, I created a simple CLI to cross-post my articles on these platforms easily. You can find it on[NPM](https://www.npmjs.com/package/cross-post-blog)and check the code on[GitHub](https://github.com/shahednasser/cross-post#readme).

---

## Installation

In your terminal:

```
npm i -g cross-post-blog
```

---

## Usage

### Set Configuration

For the simplicity of the CLI, and considering most of the APIs of each of the platforms do not allow or provide endpoints for user authentication, you will need to get your access tokens, API keys, or integration tokens from your own profile before using cross-post. This will just need to be done the first time or if you want to change the tokens.

**The tokens are all stored on your local machine.**

Here's a guide on how to do this for each of the platforms:

### dev.to

After logging into your account on dev.to, click on your profile image and then click on Settings

![Settings](https://github.com/shahednasser/cross-post/raw/master/assets/dev-1.png)

Then, click on the Accounts tab in the sidebar

![Accounts](https://github.com/shahednasser/cross-post/raw/master/assets/dev-2.png)

Scroll down to the "DEV Community API Keys" section. You need to generate a new key. Enter "Cross Post" in the description text box or any name you want then click "Generate API key"

![Generate API Key](https://github.com/shahednasser/cross-post/raw/master/assets/dev-3.png)

Copy the generated API key, then in your terminal:

```
cross-post config dev
```

You'll be prompted to enter the API key. Paste the API key you copied earlier and hit enter. The API key will be saved.

### Hashnode

After logging into your account on Hashnode, click on your profile image and then click on "Account Settings"

![Settings](https://github.com/shahednasser/cross-post/raw/master/assets/Hashnode-1.png)

In the sidebar click on "Developer"

![Developer](https://github.com/shahednasser/cross-post/raw/master/assets/Hashnode-2.png)

Click the "Generate" button and then copy the generated access token.

![Generate](https://github.com/shahednasser/cross-post/raw/master/assets/Hashnode-3.png)

Run the following in your terminal:

```
cross-post config hashnode
```

First, you'll be prompted to enter your access token. Then, you need to enter your Hashnode username. The reason behind that is that when later posting on hashnode your publication id is required, so your username will be used here to retrieve the publication id. Once you do and everything goes well, the configuration will be saved successfully.

### Medium

After logging into Medium, click on your profile image and then click on "Settings"

![Settings](https://github.com/shahednasser/cross-post/raw/master/assets/Medium-1.png)

Then click on "Integration Tokens" in the sidebar

![Integration Tokens](https://github.com/shahednasser/cross-post/raw/master/assets/Medium-2.png)

You have to enter the description of the token then click "Get integration token" and copy the generated token.

![Generate token](https://github.com/shahednasser/cross-post/raw/master/assets/Medium-3.png)

In your terminal run:

```
cross-post config medium
```

Then enter the integration token you copied. A request will also be sent to Medium to get your authorId as it will be used later to post your article on Medium. Once that is done successfully, your configuration will be saved.

---

### Cross-Posting Your Articles

To cross-post your articles, you will use the following command:

```
cross-post run <url> [options]
```

Where`url` is the URL of your article that you want to cross-post.`options` can be:

1. `-p, --platforms [platforms...]` The platform(s) you want to post the article on. By default, if this option is not included, it will be posted on all the platforms. An example of its usage:

```
cross-post run <url> -p dev hashnode
```

1. `-t, --title [title]` The title by default will be taken from the URL you supplied, however, if you want to use a different title you can supply it in this option.
2. `-s, --selector [selector]` by default, the `article` selector will be used to find your article in the URL you pass as an argument. However, if you need a different selector to be used to find the article, you can pass it here.

This command will find the HTML element in the URL page you pass as an argument and if found, it will extract the title (if no title is passed in the arguments) and cover the image.

It should be noted that on all platforms the article will be posted as a draft, however, due to the limitations of the Hashnode API, it will be posted as "hidden from Hashnode" but it will be public in your publication.

**UPDATE:** In the latest version of this library, you can now pass the option `-pu, --public` to publish the article publicly.

---

### Conclusion

If you find any bugs or have any ideas you would like to contribute, please do so on the issues tab in the[GitHub Repository](https://github.com/shahednasser/cross-post)!