Open the command prompt and navigate to the project directory. Now, install npm dependencies by using the following command:

npm install

Run Contentstack DataSync

Now start Contentstack DataSync by executing the following command.

Note: In the following command, we have used the development environment. You need to replace 'development' with your environment name.

On Linux:

NODE_ENV=development npm start

On Windows:

set NODE_ENV=development&& npm start

After running the above command, the server starts on port 5000 and all the published items of your stack syncs on your infrastructure.

If your environment has any published content, the sync utility creates a _contents folder in your project, storing assets inside the _content/en-us/assets folder and entries inside the _content/en-us/data folder.

Install and run ngrok (for localhost only)

Note: If you using a deployment environment, such as production, you don't need ngrok. Skip this step and move to creating a webhook. Else, follow this step.

Contentstack DataSync is a webhook-based utility, and webhooks get triggered only on public domains. So, if you are setting up Contentstack DataSync on your local machine, you will require a public domain to receive webhook notifications.

ngrok creates a public URL for your localhost and creates a secure tunnel between the two. So, you need to:

Note: Make a note of the 'Forwarding URL', you will need this URL while creating webhooks. Also, DO NOT close the ngrok console during the process, else Contentstack DataSync will not receive webhook notifications.

Create a webhook:

Log in to your Contentstack account and click on the 'Settings' icon.

Select Webhooks and click on + New Webhook.

On the Create Webhook page, enter a specific name for your webhook and inside the URL to notify field, provide the ngrok URL (generated in the above step) and append '/notify' to the URL (for example, 'https://ca1a27e9.ngrok.io/notify').

Note: If you using a deployment environment, such as 'production', you will have to provide the public URL of your environment inside the URL to notify field (for example, 'https://(your_environment_name).com/notify'.)

In the When section, click on the Code View option and paste the following code snippet in it: