You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: umbraco-heartcore/client-libraries/node-js.md
+22-13Lines changed: 22 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ description: >-
6
6
7
7
# Node.js Client library
8
8
9
-
This article showcases how to fetch content and media from your Umbraco Heartcore project using the official Node.js Client Library. If you are unfamiliar with Node.js you can take a look at the [official Node.js Documentation](https://nodejs.org/en/docs/).
9
+
This article showcases how to fetch content and media from your Umbraco Heartcore project using the official Node.js Client Library. If you are not familiar with **Node.js** you can take a look at the official [Node.js Documentation](https://nodejs.org/en/docs/).
10
10
11
11
## Prerequisites
12
12
@@ -18,14 +18,17 @@ This article showcases how to fetch content and media from your Umbraco Heartcor
18
18
## Step 1: Create Content and Media in Your Heartcore Project
19
19
20
20
1. Log into your Heartcore project on the Umbraco Cloud Portal.
21
-
2. Navigate to the Content section and create a new content item, such as a "Home Page." Fill in necessary fields and publish the item.
22
-
3. Go to the Media section, upload an image, and ensure it is saved and published.
23
-
4. Note the content’s URL and media ID for fetching via the Node.js client.
21
+
2. Navigate to the Content section.
22
+
3. Create a new content item, such as a "Home Page." Fill in the necessary fields and publish it.
23
+
4. Go to the Media section.
24
+
5. Upload an image.
25
+
6. Note the content’s URL and media ID for fetching via the Node.js client.
24
26
25
27
## Step 2: Initialize a Node.js Project
26
28
27
-
1. Open a terminal or command prompt and navigate to the directory where you want your project to reside.
28
-
2. Run the following command to create a `package.json` file:
29
+
1. Open a terminal or command prompt.
30
+
2. Navigate to the directory where you want your project to reside.
31
+
3. Run the following command to create a `package.json` file:
29
32
30
33
```bash
31
34
npm init -y
@@ -35,9 +38,7 @@ npm init -y
35
38
36
39
There are two ways to install the Umbraco Headless Client Library:
37
40
38
-
- Clone or download the [Umbraco.Headless.Client.NodeJs](https://github.com/umbraco/Umbraco.Headless.Client.NodeJs) client library from GitHub.
39
-
40
-
or
41
+
- Clone or download the [Umbraco.Headless.Client.NodeJs](https://github.com/umbraco/Umbraco.Headless.Client.NodeJs) client library from GitHub, or
## Step 4: Write the code to Fetch Content and Media
49
50
50
51
1. Create a new file called `app.js` using a text editor (such as Notepad++ or Visual Studio Code) in your project directory.
51
-
2. Open the `app.js` file and use the following code template:
52
+
2. Open the `app.js` file.
53
+
3. Use the following code template:
52
54
53
55
```js
54
56
//Importing the Client Library
@@ -86,7 +88,8 @@ run()
86
88
## Step 5: Run the Script
87
89
88
90
1. Open a terminal.
89
-
2. Navigate to your project folder and run the following command:
91
+
2. Navigate to your project folder.
92
+
3. Run the following command:
90
93
91
94
```bash
92
95
node app.js
@@ -97,14 +100,20 @@ node app.js
97
100
98
101
The Node.js library provides a variety of methods to fetch and manage data from your Umbraco Heartcore project. These methods allow you to interact with both the Content Delivery API and the Content Management API, depending on your requirements.
99
102
100
-
### Calls to the Content Delivery API
103
+
### Content Delivery API
101
104
102
105
To fetch content or media, use the following convention:
103
106
104
107
```js
105
108
client.delivery.content.root();
106
109
107
110
client.delivery.media.root();
111
+
112
+
client.delivery.content.ancestors(contentId);
113
+
114
+
client.delivery.content.children(parentId);
115
+
116
+
client.delivery.content.byId(contentId);
108
117
```
109
118
110
119
In the above examples:
@@ -114,7 +123,7 @@ In the above examples:
114
123
115
124
For a full list of available methods, visit the [Content Delivery API sample repository on GitHub](https://github.com/umbraco/Umbraco.Headless.Client.NodeJs#content-delivery).
116
125
117
-
### Calls to the Content Management API
126
+
### Content Management API
118
127
119
128
To manage content, media, and other types, use the following convention:
0 commit comments