Skip to content

Commit

Permalink
Fixed steps and added more code methods
Browse files Browse the repository at this point in the history
  • Loading branch information
eshanrnh committed Dec 4, 2024
1 parent 7a17672 commit a8cadf5
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions umbraco-heartcore/client-libraries/node-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: >-

# Node.js Client library

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

## Prerequisites

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

1. Log into your Heartcore project on the Umbraco Cloud Portal.
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.
3. Go to the Media section, upload an image, and ensure it is saved and published.
4. Note the content’s URL and media ID for fetching via the Node.js client.
2. Navigate to the Content section.
3. Create a new content item, such as a "Home Page." Fill in the necessary fields and publish it.
4. Go to the Media section.
5. Upload an image.
6. Note the content’s URL and media ID for fetching via the Node.js client.

## Step 2: Initialize a Node.js Project

1. Open a terminal or command prompt and navigate to the directory where you want your project to reside.
2. Run the following command to create a `package.json` file:
1. Open a terminal or command prompt.
2. Navigate to the directory where you want your project to reside.
3. Run the following command to create a `package.json` file:

```bash
npm init -y
Expand All @@ -35,9 +38,7 @@ npm init -y

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

- Clone or download the [Umbraco.Headless.Client.NodeJs](https://github.com/umbraco/Umbraco.Headless.Client.NodeJs) client library from GitHub.

or
- Clone or download the [Umbraco.Headless.Client.NodeJs](https://github.com/umbraco/Umbraco.Headless.Client.NodeJs) client library from GitHub, or

- Run the following command in your terminal:

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

1. Create a new file called `app.js` using a text editor (such as Notepad++ or Visual Studio Code) in your project directory.
2. Open the `app.js` file and use the following code template:
2. Open the `app.js` file.
3. Use the following code template:

```js
//Importing the Client Library
Expand Down Expand Up @@ -86,7 +88,8 @@ run()
## Step 5: Run the Script

1. Open a terminal.
2. Navigate to your project folder and run the following command:
2. Navigate to your project folder.
3. Run the following command:

```bash
node app.js
Expand All @@ -97,14 +100,20 @@ node app.js

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.

### Calls to the Content Delivery API
### Content Delivery API

To fetch content or media, use the following convention:

```js
client.delivery.content.root();

client.delivery.media.root();

client.delivery.content.ancestors(contentId);

client.delivery.content.children(parentId);

client.delivery.content.byId(contentId);
```

In the above examples:
Expand All @@ -114,7 +123,7 @@ In the above examples:

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

### Calls to the Content Management API
### Content Management API

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

Expand Down

0 comments on commit a8cadf5

Please sign in to comment.