Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions pages/client-libraries/javascript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import CodeSnippet from '/components/code-snippet/CodeSnippet'
Learn how to create a JavaScript application that connects to the
Memgraph database and executes simple queries.

Running queries directly from a web browser is **not
recommended** because of additional requirements and possible
performance issues. In other words, we encourage you to use
server-side libraries and clients for top performance whenever
possible.
Run the driver in a server-side application where you can. A page in a web
browser can connect to Memgraph too, but the database credentials end up in
client-side code, and a page served over HTTPS can't connect directly. See
[Connect from a web browser](#connect-from-a-web-browser).


## Quickstart
Expand Down Expand Up @@ -291,6 +290,24 @@ Then, you can connect to the database with the following snippet:
For more details on how to create user with credentials and set authentication,
visit the [Memgraph authentication guide](/database-management/authentication-and-authorization/users#administer-users).

### Connect from a web browser

In a web browser, the JavaScript driver connects over WebSocket instead of a
TCP socket. Memgraph accepts WebSocket connections on the Bolt port (7687 by
default), so a page served over HTTP connects with the same `bolt://` URI and
code as in [Database connection](#database-connection).

Memgraph accepts WebSocket connections on the Bolt port only when SSL is
disabled. If Memgraph runs with the `--bolt-cert-file` and `--bolt-key-file`
flags, browser connections fail, because the Bolt port has no secure WebSocket
(`wss://`). Without SSL, the connection is unencrypted (`ws://`), and browsers
block unencrypted WebSocket connections from pages served over HTTPS.

To query Memgraph from a page served over HTTPS, have the page call your own
backend over HTTPS, and query Memgraph from the backend with the driver.
Keeping Memgraph behind a backend is good practice in any case: the database
credentials stay on the server, and Memgraph isn't reachable from the browser.

### Query the database

After connecting your driver to Memgraph, you can start running queries.
Expand Down
9 changes: 8 additions & 1 deletion pages/database-management/ssl-encryption.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ SSLMode::Require` to the `ConnectParams`.
</Tabs.Tab>
<Tabs.Tab>

WebSocket over SSL is currently not supported in Memgraph.
When SSL is enabled, the Bolt port doesn't accept WebSocket connections, so
JavaScript applications in a web browser can't connect over secure WebSocket
(`wss://`). To query Memgraph from a page served over HTTPS, see [Connect from
a web browser](/client-libraries/javascript#connect-from-a-web-browser).

The [log WebSocket server](/database-management/monitoring#real-time-logs-tracking-via-websocket-server)
on port 7444 uses the same certificate. When SSL is enabled, connect to it
with `wss://`.

</Tabs.Tab>
</Tabs>
Expand Down
Loading