Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @hackmd/hackmd-cli with all npm packages installed. Try it out:

var hackmdCli = require("@hackmd/hackmd-cli")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@hackmd/hackmd-cli v1.1.1

hackmd-cli - The HackMD/CodiMD Command Line Tool

oclif Version Downloads/week License

Usage

```sh-session $ npm install -g @hackmd/hackmd-cli $ hackmd-cli COMMAND running command... $ hackmd-cli (-v|--version|version) @hackmd/hackmd-cli/1.1.1 darwin-x64 node-v12.16.2 $ hackmd-cli --help [COMMAND] USAGE $ hackmd-cli COMMAND ... ```

Configuration

hackmd-cli operates on official HackMD instance(hackmd.io) by default. If you want to use cli with a self-hosted CodiMD or a HackMD EE instance, you will need to configure hackmd-cli by either environment variable or JSON configuration.

Example 1: Use with self-hosted CodiMD instance

Set environment variable in your shell profile:

export CMD_CLI_SERVER_URL=https://my.codimd-domain.dev

Or in JSON file (~/.hackmd/config.json):

{
  "serverUrl": "https://my.codimd-domain.dev",
  "enterprise": false
}

Example 2: Use with HackMD EE

Set environment variable in your shell profile:

export HMD_CLI_SERVER_URL=https://my.hackmd-ee.domain

Or in JSON file (~/.hackmd/config.json):

{
  "serverUrl": "https://https://my.hackmd-ee.domain"
}

Configuration Reference

All available configurations are listed in the table below.

Config keyEnvironment VariableData TypeExample ValueDescription
serverUrlHMD_CLI_SERVER_URL or CMD_CLI_SERVER_URLstringhttps://my.codimd-domain.devThe instance URL
cookiePathHMD_CLI_COOKIE_PATH or CMD_CLI_COOKIE_PATHstring~/.hackmd/cookies.jsonFile for storing login cookie states
enterprisen/abooleantrueSet whether the instance is enterise version expclitly. This config can only be set in JSON based config. When providing server url with environment variable, enterprise will be automatically set by checking the env prefix(HMD or CMD)
n/aHMD_CLI_ID or CMD_CLI_IDstringme@codimd-domain.devLogin username/email
n/aHMD_CLI_PASSWORD or CMD_CLI_PASSWORDstringdragonLogin password

Don't commit your login credentials!

Commands

* [`hackmd-cli export [NOTEID] [OUTPUT]`](#hackmd-cli-export-noteid-output) * [`hackmd-cli help [COMMAND]`](#hackmd-cli-help-command) * [`hackmd-cli history`](#hackmd-cli-history) * [`hackmd-cli import [FILE]`](#hackmd-cli-import-file) * [`hackmd-cli login`](#hackmd-cli-login) * [`hackmd-cli logout`](#hackmd-cli-logout) * [`hackmd-cli teams`](#hackmd-cli-teams) * [`hackmd-cli whoami`](#hackmd-cli-whoami)

hackmd-cli export [NOTEID] [OUTPUT]

Export note to local file or stdout(if the output_file param is omitted)

USAGE
  $ hackmd-cli export [NOTEID] [OUTPUT]

OPTIONS
  -h, --help  show CLI help
  --html
  --md
  --pdf

EXAMPLE
  $ hackmd-cli export [--pdf|--md|--html] <note_id> <output_file>

See code: src/commands/export.ts

hackmd-cli help [COMMAND]

display help for hackmd-cli

USAGE
  $ hackmd-cli help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

hackmd-cli history

List history

USAGE
  $ hackmd-cli history

OPTIONS
  -h, --help              show CLI help
  -x, --extended          show extra columns
  --columns=columns       only show provided columns (comma-separated)
  --csv                   output is csv format [alias: --output=csv]
  --filter=filter         filter property by partial string matching, ex: name=foo
  --no-header             hide table header from output
  --no-truncate           do not truncate output to fit screen
  --output=csv|json|yaml  output in a more machine friendly format
  --sort=sort             property to sort by (prepend '-' for descending)

EXAMPLE
  $ hackmd-cli history

  ID                     Name
  A58r8ehYTlySO94oiC_MUA Note1
  EeNHDGocSTi70ytMMGQaaQ Note2

See code: src/commands/history.ts

hackmd-cli import [FILE]

Create a note from markdown file

USAGE
  $ hackmd-cli import [FILE]

OPTIONS
  -h, --help       show CLI help
  -t, --team=team  team to use

EXAMPLE
  $ hackmd-cli import /path/to/markdown/file.md --team=xxx

  Your note is available at https://hackmd.io/note-url

See code: src/commands/import.ts

hackmd-cli login

Login to HackMD/CodiMD server from CLI

USAGE
  $ hackmd-cli login

OPTIONS
  -h, --help   show CLI help
  -u, --id=id  Login email/username
  --ldap

EXAMPLE
  $ hackmd-cli login

  Enter your email: hello@hackmd.io
  Enter your password: *******

  Login as HMD successfully!

See code: src/commands/login.ts

hackmd-cli logout

Logout from CLI

USAGE
  $ hackmd-cli logout

OPTIONS
  -h, --help  show CLI help

EXAMPLE
  $ hackmd-cli logout

  You've logged out successfully

See code: src/commands/logout.ts

hackmd-cli teams

HackMD Teams Command

USAGE
  $ hackmd-cli teams

OPTIONS
  -h, --help              show CLI help
  -x, --extended          show extra columns
  --columns=columns       only show provided columns (comma-separated)
  --csv                   output is csv format [alias: --output=csv]
  --filter=filter         filter property by partial string matching, ex: name=foo
  --no-header             hide table header from output
  --no-truncate           do not truncate output to fit screen
  --output=csv|json|yaml  output in a more machine friendly format
  --sort=sort             property to sort by (prepend '-' for descending)

EXAMPLE
  $ hackmd-cli teams

  Path            Name
  team1           Team 1
  my-awesome-team My Awesome Team

See code: src/commands/teams.ts

hackmd-cli whoami

Show logged in account info

USAGE
  $ hackmd-cli whoami

OPTIONS
  -h, --help  show CLI help

EXAMPLE
  $ hackmd-cli whoami

  You are logged in hackmd.io as {YOUR NAME} [user-id]

See code: src/commands/whoami.ts

hackmd-cli piping mode

You can create a note by piping text stream to hackmd-cli

USAGE
  $ hackmd-cli [COMMAND]

EXAMPLE
  $ cat README.md | hackmd-cli

  Your note is available at https://hackmd.io/note-url

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free