Skip to content

Commit a8cadf5

Browse files
committed
Fixed steps and added more code methods
1 parent 7a17672 commit a8cadf5

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

umbraco-heartcore/client-libraries/node-js.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: >-
66

77
# Node.js Client library
88

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/).
1010

1111
## Prerequisites
1212

@@ -18,14 +18,17 @@ This article showcases how to fetch content and media from your Umbraco Heartcor
1818
## Step 1: Create Content and Media in Your Heartcore Project
1919

2020
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.
2426

2527
## Step 2: Initialize a Node.js Project
2628

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:
2932

3033
```bash
3134
npm init -y
@@ -35,9 +38,7 @@ npm init -y
3538

3639
There are two ways to install the Umbraco Headless Client Library:
3740

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
4142

4243
- Run the following command in your terminal:
4344

@@ -48,7 +49,8 @@ npm install @umbraco/headless-client
4849
## Step 4: Write the code to Fetch Content and Media
4950

5051
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:
5254

5355
```js
5456
//Importing the Client Library
@@ -86,7 +88,8 @@ run()
8688
## Step 5: Run the Script
8789

8890
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:
9093

9194
```bash
9295
node app.js
@@ -97,14 +100,20 @@ node app.js
97100

98101
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.
99102

100-
### Calls to the Content Delivery API
103+
### Content Delivery API
101104

102105
To fetch content or media, use the following convention:
103106

104107
```js
105108
client.delivery.content.root();
106109

107110
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);
108117
```
109118

110119
In the above examples:
@@ -114,7 +123,7 @@ In the above examples:
114123

115124
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).
116125

117-
### Calls to the Content Management API
126+
### Content Management API
118127

119128
To manage content, media, and other types, use the following convention:
120129

0 commit comments

Comments
 (0)