<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>State management with the Dapr JavaScript SDK on Dapr Docs</title><link>https://docs.dapr.io/developing-applications/sdks/js/js-state-management/</link><description>Recent content in State management with the Dapr JavaScript SDK on Dapr Docs</description><generator>Hugo</generator><language>en</language><atom:link href="https://docs.dapr.io/developing-applications/sdks/js/js-state-management/index.xml" rel="self" type="application/rss+xml"/><item><title>How to: Manage state with the Dapr JavaScript SDK</title><link>https://docs.dapr.io/developing-applications/sdks/js/js-state-management/js-state-management-howto/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://docs.dapr.io/developing-applications/sdks/js/js-state-management/js-state-management-howto/</guid><description>&lt;p>Use &lt;code>DaprClient.state&lt;/code> to manage key/value application state without depending on a particular database client. This guide uses Redis and covers basic operations, optimistic concurrency, bulk operations, TTL, and transactions.&lt;/p>
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://docs.dapr.io/getting-started/install-dapr-cli/">Dapr CLI&lt;/a>&lt;/li>
&lt;li>An initialized &lt;a href="https://docs.dapr.io/getting-started/install-dapr-selfhost/">Dapr environment&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://nodejs.org/">Node.js&lt;/a> 18 or later&lt;/li>
&lt;li>The &lt;a href="https://www.npmjs.com/package/@dapr/dapr">&lt;code>@dapr/dapr&lt;/code>&lt;/a> package, version 3.19.0 or later&lt;/li>
&lt;li>A Redis instance, such as the local Redis container created by &lt;code>dapr init&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>In your application directory, initialize an npm project if needed and install the SDK:&lt;/p></description></item><item><title>State client usage</title><link>https://docs.dapr.io/developing-applications/sdks/js/js-state-management/js-state-management-client-usage/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://docs.dapr.io/developing-applications/sdks/js/js-state-management/js-state-management-client-usage/</guid><description>&lt;p>State management is available through &lt;code>DaprClient.state&lt;/code>. This page describes the implementation in 3.19.0 and the behavior to account for when using that package or a later compatible release.&lt;/p>
&lt;h2 id="client-lifetime-and-configuration">Client lifetime and configuration&lt;/h2>
&lt;p>Reuse a long-lived &lt;code>DaprClient&lt;/code> instead of constructing one per operation. Await outstanding requests before calling &lt;code>await client.stop()&lt;/code> during shutdown.&lt;/p>
&lt;p>HTTP is the default protocol. To use gRPC:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">CommunicationProtocolEnum&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">DaprClient&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="nx">from&lt;/span> &lt;span class="s2">&amp;#34;@dapr/dapr&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">const&lt;/span> &lt;span class="nx">client&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">new&lt;/span> &lt;span class="nx">DaprClient&lt;/span>&lt;span class="p">({&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">daprHost&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s2">&amp;#34;127.0.0.1&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">daprPort&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s2">&amp;#34;50001&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">communicationProtocol&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="nx">CommunicationProtocolEnum&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">GRPC&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">daprApiToken&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="nx">process&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">env&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">DAPR_API_TOKEN&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>For HTTP, use &lt;code>CommunicationProtocolEnum.HTTP&lt;/code> and the sidecar&amp;rsquo;s HTTP port, normally &lt;code>&amp;quot;3500&amp;quot;&lt;/code>. Port options are strings.&lt;/p></description></item><item><title>How to: Query state with the Dapr JavaScript SDK</title><link>https://docs.dapr.io/developing-applications/sdks/js/js-state-management/js-state-management-query/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://docs.dapr.io/developing-applications/sdks/js/js-state-management/js-state-management-query/</guid><description>&lt;p>Use &lt;code>client.state.query&lt;/code> to query JSON documents in a state store that supports the &lt;a href="https://docs.dapr.io/developing-applications/building-blocks/state-management/howto-state-query-api/">state query API&lt;/a>. Both HTTP and gRPC are implemented in 3.19.0. This is the &lt;strong>alpha&lt;/strong> state query API, not a general-purpose SQL or native database query interface.&lt;/p>
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>
&lt;p>Follow the &lt;a href="https://docs.dapr.io/developing-applications/sdks/js/js-state-management/js-state-management-howto/">state management how-to&lt;/a> to install the SDK and run an application with a sidecar. For this guide, configure a query-capable component named &lt;code>state-mongodb&lt;/code>, following the &lt;a href="https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-mongodb/">MongoDB state store reference&lt;/a>. The basic Redis component in the how-to does not by itself configure query support.&lt;/p></description></item></channel></rss>