npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-discourse-api

v0.1.5

Published

A node api for discourse

Downloads

18

Readme

node-discourse-api

Unofficial, Discourse Api wrapper for Node

This package is a work in progress and a large number of features are still under development. If you need to add functionality, please pull request to add a new method, or use api._request to request any API endpoint.

⚠️IMPORTANT: Regarding version numbers, any version before releasing version 1.0.0 SHOULD NOT be considered a stable version and we MAY change the API and cause incompatibilities. When there is an incompatible API, we will increment the minor version. When a new API is covered, we will increment the patch version.

build status doc status lint status

Home page

API documentation

Development Progress

❌: Not started yet
🟩: Work in progress
✅: Completed

| API | Progress | | ---------------- | -------- | | Backups | ❌ | | Badges | ❌ | | Categories | ❌ | | Groups | ❌ | | Invites | ❌ | | Notifications | ✅ | | Posts | ✅ | | Topics | 🟩 | | Private Messages | ❌ | | Search | ❌ | | Site | ✅ | | Tags | ❌ | | Uploads | 🟩 | | Users | 🟩 | | Admin | ❌ | | Chat | 🟩 | | Webhook | 🟩 |

How to use

Installation

npm install node-discourse-api

Example

Start

const { DiscourseApi } = require("node-discourse-api");

const api = new DiscourseApi("https://discourse.example.com");

// API configured by Discourse administrator. You can also leave it unset and have the API read only the public content of your forum.
api.options.api_username = "API_USERNAME";
api.options.api_key = "API_KEY";

Create a topic, Post a reply

// Create a new topic, then print it to console
api
  .createTopicPostPM({
    raw: "This is a post from node-discourse-api!!!",
    title: "Hello world!!!",
  })
  .then((post) => {
    console.log(post);
  });
// Post a reply
api.createTopicPostPM({
  raw: "This is a reply post from node-discourse-api!!!",
  topic_id: 1,
});
// Reply to a post
api.createTopicPostPM({
  raw: "This is a reply of reply from node-discourse-api!!!",
  topic_id: 1,
  reply_to_post_number: 2,
});
// Handling errors
api
  .createTopicPostPM({
    raw: "This reply cannot be sent",
    topic_id: -123,
  })
  .catch((err) => {
    console.log("Catched a error");
    console.error(err);
  });

Send a message in channel

// Send a message in channel 2. Probably, it's #general
api.chat.sendMessage(2, "hello, world!");

Generate user api key

const { DiscourseApi } = require("node-discourse-api");

const api = new DiscourseApi("https://discourse.example.com");

const generated = api.generateUserApiKeySync();

console.log(
  "Please visit the following URL authorization and paste the generated key in the console:",
);
console.log(generated.url);

const readline = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

readline.question(`Paste key: `, (key) => {
  const decrypted = api.decryptUserApiKey(generated.private_key, key);
  console.log(decrypted);

  api.options.user_api_key = decrypted.key;

  api.createTopicPostPM({
    raw: "This is a post from node-discourse-api!!!",
    title: "Hello world!!!",
  });

  readline.close();
});

For more examples, see the API documentation

Contribute to this project

Initialize

We have set up some git hooks to help maintain code quality. If you would like to contribute to this project, please initialize in this order

git clone https://github.com/Lhcfl/node-discourse-api
cd node-discourse-api
yarn install
yarn devprepare

Test and autofix

Test code:

yarn test

autofix:

yarn autofix