DEV Community

loading...
Cover image for Try the new Dev.to Node.js SDK

Try the new Dev.to Node.js SDK

khaosdoctor profile image Lucas Santos ใƒป1 min read

As a writer and a JS developer, I always wanted to integrate the way I wrote into my code. I wanted to post articles on dev.to as soon as I finished writing them in Markdown on my editor, I wanted to integrate.

The problem is that we have a pretty good Dev.to API! But I'd need to reimplement it every time. So, I won't be writing much more on this, but I decided to create my own SDK which mirrors the spec of the API into easily usable functions.

So I'm disclosing it here! It's been a while now, a few people have been using it so it's pretty stable. But, if you ever find any bugs, feel free to send me an issue or open a PR <3

devto-nodejs-sdk

The Node.js SDK for @thepracticaldev

Installation

Install it via your favorite package manager:

npm i devto-nodejs-sdk

Usage

This is a very simple SDK tool that implements all the Swagger specs into a Node.js client. You can instantiate the client using:

import { Client } from 'devto-nodejs-sdk'
const client = new Client('Your API Key')
const { data } = await client.getUserByName('khaosdoctor')

The client itself is just a proxy of the original API.

If the API changes and you notice it, please submit an issue or, if you already know what changed, please submit a PR

API

All provided APIs in the official docs are provided as part of the API as well, these are the translated names for these endpoints:

  • listArticles
  • createArticle
  • getArticle
  • updateArticle
  • selfArticles
  • selfPublishedArticles
  • selfUnpublishedArticles
  • selfAllArticles
  • listArticleComments
  • getComment
  • listListings
  • createListing
  • getListingByCategory
  • getListingById
  • updateListing
  • getPodcastEpisodes
  • getArticleTags
  • getUserById
  • getUserByName
  • getSelfInformation
  • getArticlesWithVideo
  • getWebhooks
  • โ€ฆ

I hope you all like it! Give it a star if you do! All feedbacks are much appreciated!

Discussion

pic
Editor guide
Collapse
maxime1992 profile image
Maxime

Hi Lucas, nice thinking with the SDK ๐Ÿ˜€

If you want I've also built something but the goal is only to have a one way publishing to dev.to so that either locally or from CI you can publish your article.

dev.to/maxime1992/manage-your-dev-...

The cool thing about it is that you can have one (open source?) repo containing all your blog posts and put a link in all your articles so that people can open a PR if they spot mistakes or want to propose a fix on something that has changed etc. You can then only review the diff on Github, Gitlab or wherever you host your articles and as soon as you merge something it'll auto deploy/update only the articles which should be updated ๐Ÿ˜

BTW I'm not trying to hijack your post, I think we've built 2 different things with a different focus and it may be useful ๐Ÿ˜Š

Collapse
khaosdoctor profile image
Lucas Santos Author

Hey! This is awesome man! I was building something similar with a coworker, but you nailed it! I already have my own blog so, for now, it doesn't make much sense to me since I'm using the RSS to publish in both places. But this is something that I was really trying to use some months back.

Nice work!

Collapse
maxime1992 profile image
Maxime

Thanks! Just as an FYI I think that if you were to use it you'd also be able to use the RSS feed from dev.to ๐Ÿ˜€