Node.js Client library
Learn how to fetch content and media from your Umbraco Heartcore project using Node.js and the Umbraco.Headless.Client.NodeJs Library.
Last updated
Was this helpful?
Learn how to fetch content and media from your Umbraco Heartcore project using Node.js and the Umbraco.Headless.Client.NodeJs Library.
Last updated
Was this helpful?
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 .
(version 10 or above) installed on your machine. You can verify the version by running node -v
in your terminal.
Access to an Umbraco Heartcore project.
An API key generated from your Heartcore project. For more information, see the article.
Basic familiarity with terminal commands and Node.js.
Log into your Heartcore project on the Umbraco Cloud Portal.
Navigate to the Content section.
Create a new content item, such as a "Home Page." Fill in the necessary fields and publish it.
Go to the Media section.
Upload an image.
Note the content’s URL and media ID for fetching via the Node.js client.
Open a terminal or command prompt.
Navigate to the directory where you want your project to reside.
Run the following command to create a package.json
file:
There are two ways to install the Umbraco Headless Client Library:
Run the following command in your terminal:
Create a new file called app.js
using a text editor (such as Notepad++ or Visual Studio Code) in your project directory.
Open the app.js
file.
Use the following code template:
Open a terminal.
Navigate to your project folder.
Run the following command:
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.
To fetch content or media, use the following convention:
In the above examples:
Use root()
to fetch all content or media from the root level.
Use children()
or ancestors()
to navigate the hierarchy and retrieve related content or media items. You can also fetch specific items directly by their ID or URL.
To manage content, media, and other types, use the following convention:
In the above examples:
Use create()
to add new content.
Use all()
to fetch all available content types.
Clone or download the client library from GitHub, or
For a full list of available methods, visit the .
For a full list of available methods, visit the .