Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.

Repository files navigation

HackMD

Standard - JavaScript Style Guide

Join the chat at https://gitter.im/hackmdio/hackmdbuild status

HackMD lets you create realtime collaborative markdown notes on all platforms.
Inspired by Hackpad, with more focus on speed and flexibility.
Still in the early stage, feel free to fork or contribute to HackMD.

Thanks for using! 😄

Before you go too far, here is the great docker repo for HackMD.
With docker, you can deploy a server in minutes without any downtime.

Heroku Deployment

You can quickly setup a sample heroku hackmd application by clicking the button below.

Deploy

We don't use LZString to compress socket.io data and DB data after version 0.5.0.
Please run the migration tool if you're upgrading from the old version.

We've dropped MongoDB after version 0.4.0.
So here is the migration tool for you to transfer the old DB data to the new DB.
This tool is also used for official service.

Browsers Requirement

  • Chrome >= 47, Chrome for Android >= 47
  • Safari >= 9, iOS Safari >= 8.4
  • Firefox >= 44
  • IE >= 9, Edge >= 12
  • Opera >= 34, Opera Mini not supported
  • Android Browser >= 4.4

Prerequisite

  • Node.js 6.x or up (test up to 7.5.0)
  • Database (PostgreSQL, MySQL, MariaDB, SQLite, MSSQL) use charset utf8
  • npm (and its dependencies, especially uWebSockets, node-gyp)

Get started

  1. Download a release and unzip or clone into a directory
  2. Enter the directory and type bin/setup, which will install npm dependencies and create configs. The setup script is written in Bash, you would need bash as a prerequisite.
  3. Setup the configs, see more below
  4. Setup environment variables which will overwrite the configs
  5. Build front-end bundle by npm run build (use npm run dev if you are in development)
  6. Run the server as you like (node, forever, pm2)

Upgrade guide

If you are upgrading HackMD from an older version, follow these steps:

  1. Fully stop your old server first (important)
  2. git pull or do whatever that updates the files
  3. npm install to update dependencies
  4. Build front-end bundle by npm run build (use npm run dev if you are in development)
  5. Modify the file named .sequelizerc, change the value of the variable url with your db connection string For example: postgres://username:password@localhost:5432/hackmd
  6. Run node_modules/.bin/sequelize db:migrate, this step will migrate your db to the latest schema
  7. Start your whole new server!

Structure

hackmd/
├── tmp/ --- temporary files
├── docs/ --- document files
├── lib/ --- server libraries
└── public/ --- client files
├── css/ --- css styles
├── js/ --- js scripts
├── vendor/ --- vendor includes
└── views/ --- view templates

Configuration files

There are some configs you need to change in the files below

./config.json ----application settings

Environment variables (will overwrite other server configs)

variablesexample valuesdescription
NODE_ENVproduction or developmentset current environment (will apply corresponding settings in the config.json)
DEBUGtrue or falseset debug mode, show more logs
HMD_DOMAINhackmd.iodomain name
HMD_URL_PATHhackmdsub url path, like www.example.com/<URL_PATH>
HMD_PORT80web app port
HMD_ALLOW_ORIGINlocalhost, hackmd.iodomain name whitelist (use comma to separate)
HMD_PROTOCOL_USESSLtrue or falseset to use ssl protocol for resources path (only applied when domain is set)
HMD_URL_ADDPORTtrue or falseset to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set)
HMD_USECDNtrue or falseset to use CDN resources or not (default is true)
HMD_ALLOW_ANONYMOUStrue or falseset to allow anonymous usage (default is true)
HMD_ALLOW_FREEURLtrue or falseset to allow new note by accessing not exist note url
HMD_DEFAULT_PERMISSIONfreely, editable, limited, locked or privateset notes default permission (only applied on signed users)
HMD_DB_URLmysql://localhost:3306/databaseset the db url
HMD_FACEBOOK_CLIENTIDno exampleFacebook API client id
HMD_FACEBOOK_CLIENTSECRETno exampleFacebook API client secret
HMD_TWITTER_CONSUMERKEYno exampleTwitter API consumer key
HMD_TWITTER_CONSUMERSECRETno exampleTwitter API consumer secret
HMD_GITHUB_CLIENTIDno exampleGitHub API client id
HMD_GITHUB_CLIENTSECRETno exampleGitHub API client secret
HMD_GITLAB_SCOPEread_user or apiGitLab API requested scope (default is api) (gitlab snippet import/export need api scope)
HMD_GITLAB_BASEURLno exampleGitLab authentication endpoint, set to use other endpoint than GitLab.com (optional)
HMD_GITLAB_CLIENTIDno exampleGitLab API client id
HMD_GITLAB_CLIENTSECRETno exampleGitLab API client secret
HMD_DROPBOX_CLIENTIDno exampleDropbox API client id
HMD_DROPBOX_CLIENTSECRETno exampleDropbox API client secret
HMD_GOOGLE_CLIENTIDno exampleGoogle API client id
HMD_GOOGLE_CLIENTSECRETno exampleGoogle API client secret
HMD_LDAP_URLldap://example.comurl of LDAP server
HMD_LDAP_BINDDNno examplebindDn for LDAP access
HMD_LDAP_BINDCREDENTIALSno examplebindCredentials for LDAP access
HMD_LDAP_TOKENSECRETsupersecretkeysecret used for generating access/refresh tokens
HMD_LDAP_SEARCHBASEo=users,dc=example,dc=comLDAP directory to begin search from
HMD_LDAP_SEARCHFILTER(uid={{username}})LDAP filter to search with
HMD_LDAP_SEARCHATTRIBUTESno exampleLDAP attributes to search with
HMD_LDAP_TLS_CAserver-cert.pem, root.pemRoot CA for LDAP TLS in PEM format (use comma to separate)
HMD_LDAP_PROVIDERNAMEMy institutionOptional name to be displayed at login form indicating the LDAP provider
HMD_IMGUR_CLIENTIDno exampleImgur API client id
HMD_EMAILtrue or falseset to allow email signin
HMD_ALLOW_EMAIL_REGISTERtrue or falseset to allow email register (only applied when email is set, default is true)
HMD_IMAGE_UPLOAD_TYPEimgur, s3 or filesystemWhere to upload image. For S3, see our S3 Image Upload Guide
HMD_S3_ACCESS_KEY_IDno exampleAWS access key id
HMD_S3_SECRET_ACCESS_KEYno exampleAWS secret key
HMD_S3_REGIONap-northeast-1AWS S3 region
HMD_S3_BUCKETno exampleAWS S3 bucket name

Application settings config.json

variablesexample valuesdescription
debugtrue or falseset debug mode, show more logs
domainlocalhostdomain name
urlpathhackmdsub url path, like www.example.com/<urlpath>
port80web app port
alloworigin['localhost']domain name whitelist
usessltrue or falseset to use ssl server (if true will auto turn on protocolusessl)
protocolusessltrue or falseset to use ssl protocol for resources path (only applied when domain is set)
urladdporttrue or falseset to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set)
usecdntrue or falseset to use CDN resources or not (default is true)
allowanonymoustrue or falseset to allow anonymous usage (default is true)
allowfreeurltrue or falseset to allow new note by accessing not exist note url
defaultpermissionfreely, editable, limited, locked, protected or privateset notes default permission (only applied on signed users)
dburlmysql://localhost:3306/databaseset the db url, if set this variable then below db config won't be applied
db{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }set the db configs, see more here
sslkeypath./cert/client.keyssl key path (only need when you set usessl)
sslcertpath./cert/hackmd_io.crtssl cert path (only need when you set usessl)
sslcapath['./cert/COMODORSAAddTrustCA.crt']ssl ca chain (only need when you set usessl)
dhparampath./cert/dhparam.pemssl dhparam path (only need when you set usessl)
tmppath./tmp/temp directory path
defaultnotepath./public/default.mddefault note file path
docspath./public/docsdocs directory path
indexpath./public/views/index.ejsindex template file path
hackmdpath./public/views/hackmd.ejshackmd template file path
errorpath./public/views/error.ejserror template file path
prettypath./public/views/pretty.ejspretty template file path
slidepath./public/views/slide.hbsslide template file path
sessionnameconnect.sidcookie session name
sessionsecretsecretcookie session secret
sessionlife14 * 24 * 60 * 60 * 1000cookie session life
staticcachetime1 * 24 * 60 * 60 * 1000static file cache time
heartbeatinterval5000socket.io heartbeat interval
heartbeattimeout10000socket.io heartbeat timeout
documentmaxlength100000note max length
emailtrue or falseset to allow email signin
allowemailregistertrue or falseset to allow email register (only applied when email is set, default is true)
imageUploadTypeimgur(default), s3 or filesystemWhere to upload image
s3{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION", "bucket": "YOUR_S3_BUCKET_NAME" }When imageUploadType be setted to s3, you would also need to setup this key, check our S3 Image Upload Guide

Third-party integration api key settings

servicesettings locationdescription
facebook, twitter, github, gitlab, dropbox, google, ldapenvironment variables or config.jsonfor signin
imgurenvironment variables or config.jsonfor image upload
google drive(google/apiKey, google/clientID), dropbox(dropbox/appKey)config.jsonfor export and import

Third-party integration oauth callback urls

servicecallback url (after the server url)
facebook/auth/facebook/callback
twitter/auth/twitter/callback
github/auth/github/callback
gitlab/auth/gitlab/callback
dropbox/auth/dropbox/callback
google/auth/google/callback

Operational Transformation

From 0.3.2, we started supporting operational transformation.
It makes concurrent editing safe and will not break up other users' operations.
Additionally, now can show other clients' selections.
See more at http://operational-transformation.github.io/

License under MIT.

About

Realtime collaborative markdown notes on all platforms.

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages