Skip to content

Repository files navigation

CodiMD

Standard - JavaScript Style Guide

Join the chat at https://gitter.im/hackmdio/hackmd#CodiMD on matrix.orgbuild statusversionHelp Contribute to Open SourcePOEditor

CodiMD lets you create real-time collaborative markdown notes on all platforms. Inspired by Hackpad, with more focus on speed and flexibility, and build from HackMD source code. Feel free to contribute.

Thanks for using! 😄

Table of Contents

HackMD CE became CodiMD

CodiMD was recently renamed from its former name was HackMD. CodiMD is the free software version of HackMD. It was the original Version of HackMD. The HackMD team initiated CodiMD and provided a solid code base. Due to the need of paying bills, A fork was created and called HackMD EE, which is a SaaS (Software as a Service) product available at hackmd.io.

We decided to change the name to break the confusion between HackMD and CodiMD, formally known as HackMD CE, as it never was an open core project.

Just to more confusion: We are still friends with HackMD ❤️

For the whole renaming story, see the related issue

Browsers Requirement

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

Installation

Getting started (Native install)

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)
  • For building CodiMD we recommend to use a machine with at least 2GB RAM

Instructions

  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. Modify the file named .sequelizerc, change the value of the variable url with your db connection string For example: postgres://username:password@localhost:5432/codimd
  7. Run node_modules/.bin/sequelize db:migrate, this step will migrate your db to the latest schema
  8. Run the server as you like (node, forever, pm2)

Heroku Deployment

You can quickly setup a sample Heroku CodiMD application by clicking the button below.

Deploy on Heroku

If you deploy it without the button, keep in mind to use the right buildpacks. For details check app.json.

Kubernetes

To install use helm install stable/hackmd.

For all further details, please check out the offical CodiMD K8s helm chart.

CodiMD by docker container

Try in PWD

Debian-based version:

latest

Alpine-based version:

alpine

The easiest way to setup CodiMD using docker are using the following three commands:

git clone https://github.com/hackmdio/docker-hackmd.gitcd docker-codimddocker-compose up

Read more about it in the docker repository…

Upgrade

Native setup

If you are upgrading CodiMD 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/codimd
  6. Run node_modules/.bin/sequelize db:migrate, this step will migrate your db to the latest schema
  7. Start your whole new server!
  • migrate-to-1.1.0

We deprecated the older lower case config style and moved on to camel case style. Please have a look at the current config.json.example and check the warnings on startup.

Notice: This is not a breaking change right now but in the future

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.

Configuration

There are some config settings 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
CMD_DOMAINcodimd.orgdomain name
CMD_URL_PATHcodimdsub URL path, like www.example.com/<URL_PATH>
CMD_PORT80web app port
CMD_ALLOW_ORIGINlocalhost, codimd.orgdomain name whitelist (use comma to separate)
CMD_PROTOCOL_USESSLtrue or falseset to use SSL protocol for resources path (only applied when domain is set)
CMD_URL_ADDPORTtrue or falseset to add port on callback URL (ports 80 or 443 won't be applied) (only applied when domain is set)
CMD_USECDNtrue or falseset to use CDN resources or not (default is true)
CMD_ALLOW_ANONYMOUStrue or falseset to allow anonymous usage (default is true)
CMD_ALLOW_ANONYMOUS_EDITStrue or falseif allowAnonymous is true, allow users to select freely permission, allowing guests to edit existing notes (default is false)
CMD_ALLOW_FREEURLtrue or falseset to allow new note creation by accessing a nonexistent note URL
CMD_DEFAULT_PERMISSIONfreely, editable, limited, locked or privateset notes default permission (only applied on signed users)
CMD_DB_URLmysql://localhost:3306/databaseset the database URL
CMD_SESSION_SECRETno exampleSecret used to sign the session cookie. If non is set, one will randomly generated on startup
CMD_SESSION_LIFE1209600000Session life time. (milliseconds)
CMD_FACEBOOK_CLIENTIDno exampleFacebook API client id
CMD_FACEBOOK_CLIENTSECRETno exampleFacebook API client secret
CMD_TWITTER_CONSUMERKEYno exampleTwitter API consumer key
CMD_TWITTER_CONSUMERSECRETno exampleTwitter API consumer secret
CMD_GITHUB_CLIENTIDno exampleGitHub API client id
CMD_GITHUB_CLIENTSECRETno exampleGitHub API client secret
CMD_GITLAB_SCOPEread_user or apiGitLab API requested scope (default is api) (GitLab snippet import/export need api scope)
CMD_GITLAB_BASEURLno exampleGitLab authentication endpoint, set to use other endpoint than GitLab.com (optional)
CMD_GITLAB_CLIENTIDno exampleGitLab API client id
CMD_GITLAB_CLIENTSECRETno exampleGitLab API client secret
CMD_MATTERMOST_BASEURLno exampleMattermost authentication endpoint
CMD_MATTERMOST_CLIENTIDno exampleMattermost API client id
CMD_MATTERMOST_CLIENTSECRETno exampleMattermost API client secret
CMD_DROPBOX_CLIENTIDno exampleDropbox API client id
CMD_DROPBOX_CLIENTSECRETno exampleDropbox API client secret
CMD_GOOGLE_CLIENTIDno exampleGoogle API client id
CMD_GOOGLE_CLIENTSECRETno exampleGoogle API client secret
CMD_LDAP_URLldap://example.comURL of LDAP server
CMD_LDAP_BINDDNno examplebindDn for LDAP access
CMD_LDAP_BINDCREDENTIALSno examplebindCredentials for LDAP access
CMD_LDAP_SEARCHBASEo=users,dc=example,dc=comLDAP directory to begin search from
CMD_LDAP_SEARCHFILTER(uid={{username}})LDAP filter to search with
CMD_LDAP_SEARCHATTRIBUTESdisplayName, mailLDAP attributes to search with (use comma to separate)
CMD_LDAP_USERIDFIELDuidNumber or uid or sAMAccountNameThe LDAP field which is used uniquely identify a user on CodiMD
CMD_LDAP_USERNAMEFIELDFallback to useridThe LDAP field which is used as the username on CodiMD
CMD_LDAP_TLS_CAserver-cert.pem, root.pemRoot CA for LDAP TLS in PEM format (use comma to separate)
CMD_LDAP_PROVIDERNAMEMy institutionOptional name to be displayed at login form indicating the LDAP provider
CMD_SAML_IDPSSOURLhttps://idp.example.com/ssoauthentication endpoint of IdP. for details, see guide.
CMD_SAML_IDPCERT/path/to/cert.pemcertificate file path of IdP in PEM format
CMD_SAML_ISSUERno exampleidentity of the service provider (optional, default: serverurl)"
CMD_SAML_IDENTIFIERFORMATno examplename identifier format (optional, default: urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress)
CMD_SAML_GROUPATTRIBUTEmemberOfattribute name for group list (optional)
CMD_SAML_REQUIREDGROUPSHackmd-usersgroup names that allowed (use vertical bar to separate) (optional)
CMD_SAML_EXTERNALGROUPSTemporary-staffgroup names that not allowed (use vertical bar to separate) (optional)
CMD_SAML_ATTRIBUTE_IDsAMAccountNameattribute map for id (optional, default: NameID of SAML response)
CMD_SAML_ATTRIBUTE_USERNAMEmailNicknameattribute map for username (optional, default: NameID of SAML response)
CMD_SAML_ATTRIBUTE_EMAILmailattribute map for email (optional, default: NameID of SAML response if CMD_SAML_IDENTIFIERFORMAT is default)
CMD_IMGUR_CLIENTIDno exampleImgur API client id
CMD_EMAILtrue or falseset to allow email signin
CMD_ALLOW_PDF_EXPORTtrue or falseEnable or disable PDF exports
CMD_ALLOW_EMAIL_REGISTERtrue or falseset to allow email register (only applied when email is set, default is true. Note bin/manage_users might help you if registration is false.)
CMD_ALLOW_GRAVATARtrue or falseset to false to disable gravatar as profile picture source on your instance
CMD_IMAGE_UPLOAD_TYPEimgur, s3, minio or filesystemWhere to upload images. For S3, see our Image Upload Guides for S3 or Minio
CMD_S3_ACCESS_KEY_IDno exampleAWS access key id
CMD_S3_SECRET_ACCESS_KEYno exampleAWS secret key
CMD_S3_REGIONap-northeast-1AWS S3 region
CMD_S3_BUCKETno exampleAWS S3 bucket name
CMD_MINIO_ACCESS_KEYno exampleMinio access key
CMD_MINIO_SECRET_KEYno exampleMinio secret key
CMD_MINIO_ENDPOINTminio.example.orgAddress of your Minio endpoint/instance
CMD_MINIO_PORT9000Port that is used for your Minio instance
CMD_MINIO_SECUREtrueIf set to true HTTPS is used for Minio
CMD_AZURE_CONNECTION_STRINGno exampleAzure Blob Storage connection string
CMD_AZURE_CONTAINERno exampleAzure Blob Storage container name (automatically created if non existent)
CMD_HSTS_ENABLE trueset to enable HSTS if HTTPS is also enabled (default is true)
CMD_HSTS_INCLUDE_SUBDOMAINStrueset to include subdomains in HSTS (default is true)
CMD_HSTS_MAX_AGE31536000max duration in seconds to tell clients to keep HSTS status (default is a year)
CMD_HSTS_PRELOADtruewhether to allow preloading of the site's HSTS status (e.g. into browsers)
CMD_CSP_ENABLEtruewhether to enable Content Security Policy (directives cannot be configured with environment variables)
CMD_CSP_REPORTURIhttps://<someid>.report-uri.com/r/d/csp/enforceAllows to add a URL for CSP reports in case of violations

Note: Due to the rename process we renamed all HMD_-prefix variables to be CMD_-prefixed. The old ones continue to work.

Application settings config.json

variablesexample valuesdescription
debugtrue or falseset debug mode, show more logs
domainlocalhostdomain name
urlPathcodimdsub 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)
hsts{"enable": true, "maxAgeSeconds": 31536000, "includeSubdomains": true, "preload": true}HSTS options to use with HTTPS (default is the example value, max age is a year)
csp{"enable": true, "directives": {"scriptSrc": "trustworthy-scripts.example.com"}, "upgradeInsecureRequests": "auto", "addDefaults": true}Configures Content Security Policy. Directives are passed to Helmet - see their documentation for more information on the format. Some defaults are added to the configured values so that the application doesn't break. To disable this behaviour, set addDefaults to false. Further, if usecdn is on, some CDN locations are allowed too. By default (auto), insecure (HTTP) requests are upgraded to HTTPS via CSP if useSSL is on. To change this behaviour, set upgradeInsecureRequests to either true or false.
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 (ports 80 or 443 won't be 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)
allowAnonymousEditstrue or falseif allowAnonymous is true: allow users to select freely permission, allowing guests to edit existing notes (default is false)
allowFreeURLtrue or falseset to allow new note creation by accessing a nonexistent 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, then db config (below) won't be applied
db{ "dialect": "sqlite", "storage": "./db.codimd.sqlite" }set the db configs, see more here
sslKeyPath./cert/client.keySSL key path (only need when you set useSSL)
sslCertPath./cert/codimd_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
uploadsPath./public/uploadsuploads directory - needs to be persistent when you use imageUploadType filesystem
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. Note bin/manage_users might help you if registration is false.)
allowGravatartrue or falseset to false to disable gravatar as profile picture source on your instance
imageUploadTypeimgur, s3, minio, azure or filesystem(default)Where to upload images. For S3, see our Image Upload Guides for S3 or Minio
minio{ "accessKey": "YOUR_MINIO_ACCESS_KEY", "secretKey": "YOUR_MINIO_SECRET_KEY", "endpoint": "YOUR_MINIO_HOST", port: 9000, secure: true }When imageUploadType is set to minio, you need to set this key. Also checkout our Minio Image Upload Guide
s3{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION" }When imageuploadtype be set to s3, you would also need to setup this key, check our S3 Image Upload Guide
s3bucketYOUR_S3_BUCKET_NAMEbucket name when imageUploadType is set to s3 or minio

Third-party integration API key settings

servicesettings locationdescription
facebook, twitter, github, gitlab, mattermost, dropbox, google, ldap, samlenvironment variables or config.jsonfor signin
imgur, s3, minio, azureenvironment variables or config.jsonfor image upload
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
mattermost/auth/mattermost/callback
dropbox/auth/dropbox/callback
google/auth/google/callback
saml/auth/saml/callback

Developer Notes

Structure

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

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

License under AGPL.

About

CodiMD - Realtime collaborative markdown notes on all platforms.

Resources

Contributing

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages