Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Server SDK Quickstarts #26

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
96 changes: 96 additions & 0 deletions src/routes/docs/quick-starts/node/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
layout: article
title: Start with Node.js
description: This is the description used for SEO.
---
Learn to setup your first Node.js project powered by Appwrite.
{% section #step-1 step=1 title="Create project" %}
Head to the [Appwrite Console](https://cloud.appwrite.io/console).

![Create project screen](/images/docs/databases/quick-start/create-project.png)

If this is your first time using Appwrite, create an account and create your first project.

Then, under **Integrate with your server**, add an **API Key**. Make sure to add the `locale.read` scope in the **Other** category (all other scopes are optional).

![Add API Key]()

{% /section %}
{% section #step-2 step=2 title="Create Node.js project" %}
Create a Node.js CLI application.

```sh
mkdir my-app
cd my-app
npm init
```

{% /section %}
{% section #step-3 step=3 title="Install Appwrite" %}

Install the Node.js Appwrite SDK.

```sh
npm install node-appwrite
```
{% /section %}
{% section #step-4 step=4 title="Import Appwrite" %}

Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier.

![Settings page in Appwrite Console.](/images/docs/databases/quick-start/project-id.png)

Create a new file `app.js` and initialize the Appwrite Client. Replace `<YOUR_PROJECT_ID>` with your project ID and `<YOUR_API_KEY>` with your API key.

```js
const sdk = require("node-appwrite");

const client = new sdk.Client();

client
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject("<YOUR_PROJECT_ID>")
.setKey("<YOUR_API_KEY>");
```

{% /section %}
{% section #step-5 step=5 title="Use Locale Service" %}

Once the Appwrite Client is set up, initialize the Locale service using the Client and use it to get a list of all countries by adding the following code to `app.js`.

```js
const locale = new sdk.Locale(client);

locale.listCountries()
.then(response => console.log(response))
.catch(error => console.log(error));
```

{% /section %}
{% section #step-6 step=6 title="Review your project" %}

Review the entire program in `app.js` once before running it. This is a good time to catch any errors that may have been made in any past step.

```js
const sdk = require("node-appwrite");

const client = new sdk.Client();

client
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject("<YOUR_PROJECT_ID>")
.setKey("<YOUR_API_KEY>");

const locale = new sdk.Locale(client);

locale.listCountries()
.then(response => console.log(response))
.catch(error => console.log(error));
```

{% /section %}
{% section #step-7 step=7 title="Checkout what you've built" %}

Run your project with `node app.js` and view the response in your console.

{% /section %}
2 changes: 1 addition & 1 deletion src/routes/docs/quick-starts/sveltekit/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Head to the [Appwrite Console](https://cloud.appwrite.io/console).

![Create project screen](/images/docs/databases/quick-start/create-project.png)

If this is your first time using Appwrite, create an accout and create your first project.
If this is your first time using Appwrite, create an account and create your first project.

Then, under **Add a platform**, add a **Web app**. The **Hostname** should be localhost.

Expand Down