"use strict";(self.webpackChunkwaku_guide=self.webpackChunkwaku_guide||[]).push([[6895],{28453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>a});var i=t(96540);const s={},r=i.createContext(s);function l(e){const n=i.useContext(r);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),i.createElement(r.Provider,{value:n},e.children)}},39789:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>o,contentTitle:()=>a,default:()=>u,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"build/javascript/local-dev-env","title":"Set Up a Local Development Environment","description":"The most reliable way to ensure your js-waku application will work in realistic conditions is to spin up a local nwaku fleet and test against it.","source":"@site/docs/build/javascript/local-dev-env.md","sourceDirName":"build/javascript","slug":"/build/javascript/local-dev-env","permalink":"/build/javascript/local-dev-env","draft":false,"unlisted":false,"editUrl":"https://github.com/waku-org/docs.waku.org/tree/develop/docs/build/javascript/local-dev-env.md","tags":[],"version":"current","lastUpdatedAt":null,"frontMatter":{"title":"Set Up a Local Development Environment"},"sidebar":"build","previous":{"title":"Scaffold DApps Using @waku/create-app","permalink":"/build/javascript/use-waku-create-app"},"next":{"title":"Bootstrap Nodes and Discover Peers","permalink":"/build/javascript/configure-discovery"}}');var s=t(74848),r=t(28453);const l={title:"Set Up a Local Development Environment"},a="Set Up a Local Development Environment",o={},d=[{value:"Requirements",id:"requirements",level:2},{value:"Quick Start",id:"quick-start",level:2},{value:"1. Start the Network",id:"1-start-the-network",level:3},{value:"2. Connect Your js-waku App",id:"2-connect-your-js-waku-app",level:3},{value:"3. Stop When Done",id:"3-stop-when-done",level:3},{value:"Available Commands",id:"available-commands",level:2},{value:"Using npx (published package)",id:"using-npx-published-package",level:3},{value:"Configuration",id:"configuration",level:2},{value:"Custom Ports",id:"custom-ports",level:3},{value:"Cluster Configuration",id:"cluster-configuration",level:3},{value:"Custom nwaku Version",id:"custom-nwaku-version",level:3},{value:"Debugging",id:"debugging",level:2},{value:"View Node Logs",id:"view-node-logs",level:3},{value:"Check Node Health",id:"check-node-health",level:3},{value:"Check Peer Connections",id:"check-peer-connections",level:3}];function c(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"set-up-a-local-development-environment",children:"Set Up a Local Development Environment"})}),"\n",(0,s.jsx)(n.p,{children:"The most reliable way to ensure your js-waku application will work in realistic conditions is to spin up a local nwaku fleet and test against it."}),"\n",(0,s.jsx)(n.h2,{id:"requirements",children:"Requirements"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"https://www.docker.com/products/docker-desktop/",children:"Docker Desktop"})," or Docker Engine with Compose plugin"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"quick-start",children:"Quick Start"}),"\n",(0,s.jsx)(n.h3,{id:"1-start-the-network",children:"1. Start the Network"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npx @waku/run start\n"})}),"\n",(0,s.jsx)(n.p,{children:"This will:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Start 2 nwaku nodes and a PostgreSQL database"}),"\n",(0,s.jsx)(n.li,{children:"Run in the background (detached mode)"}),"\n",(0,s.jsx)(n.li,{children:"Display connection information you need for your app"}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Example output:"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:'import { createLightNode } from "@waku/sdk";\n\nconst waku = await createLightNode({\n defaultBootstrap: false,\n bootstrapPeers: [\n "/ip4/127.0.0.1/tcp/60000/ws/p2p/16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2",\n "/ip4/127.0.0.1/tcp/60001/ws/p2p/16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ"\n ],\n numPeersToUse: 2,\n libp2p: {\n filterMultiaddrs: false\n },\n networkConfig: {\n clusterId: 0,\n numShardsInCluster: 8\n }\n});\n'})}),"\n",(0,s.jsx)(n.h3,{id:"2-connect-your-js-waku-app",children:"2. Connect Your js-waku App"}),"\n",(0,s.jsx)(n.p,{children:"Copy the configuration from the output above and paste it into your application. Then start your node:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"await waku.start();\n\n// Your app is now connected to your local Waku network!\n"})}),"\n",(0,s.jsx)(n.h3,{id:"3-stop-when-done",children:"3. Stop When Done"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npx @waku/run stop\n"})}),"\n",(0,s.jsx)(n.h2,{id:"available-commands",children:"Available Commands"}),"\n",(0,s.jsx)(n.h3,{id:"using-npx-published-package",children:"Using npx (published package)"}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Command"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"npx @waku/run start"})}),(0,s.jsx)(n.td,{children:"Start the network (detached) and show connection info"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"npx @waku/run stop"})}),(0,s.jsx)(n.td,{children:"Stop the network and clean up"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"npx @waku/run info"})}),(0,s.jsx)(n.td,{children:"Show connection info for running network"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"npx @waku/run logs"})}),(0,s.jsx)(n.td,{children:"View and follow logs from all nodes"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"npx @waku/run test"})}),(0,s.jsx)(n.td,{children:"Test the network by sending a message"})]})]})]}),"\n",(0,s.jsx)(n.h2,{id:"configuration",children:"Configuration"}),"\n",(0,s.jsx)(n.p,{children:"All configuration is done via environment variables passed to the command."}),"\n",(0,s.jsx)(n.h3,{id:"custom-ports",children:"Custom Ports"}),"\n",(0,s.jsx)(n.p,{children:"If the default ports are in use, specify custom ports:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"NODE1_WS_PORT=50000 NODE2_WS_PORT=50001 npx @waku/run start\n"})}),"\n",(0,s.jsx)(n.p,{children:"Available port configuration:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"NODE1_WS_PORT"})," (default: 60000)"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"NODE2_WS_PORT"})," (default: 60001)"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"NODE1_REST_PORT"})," (default: 8646)"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"NODE2_REST_PORT"})," (default: 8647)"]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"cluster-configuration",children:"Cluster Configuration"}),"\n",(0,s.jsx)(n.p,{children:"The default configuration uses:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Cluster ID: 0"}),"\n",(0,s.jsx)(n.li,{children:"Number of shards: 8"}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"To test with a different cluster:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"CLUSTER_ID=16 npx @waku/run start\n"})}),"\n",(0,s.jsx)(n.h3,{id:"custom-nwaku-version",children:"Custom nwaku Version"}),"\n",(0,s.jsx)(n.p,{children:"To use a different nwaku image version:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"NWAKU_IMAGE=wakuorg/nwaku:v0.35.0 npx @waku/run start\n"})}),"\n",(0,s.jsx)(n.h2,{id:"debugging",children:"Debugging"}),"\n",(0,s.jsx)(n.h3,{id:"view-node-logs",children:"View Node Logs"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npx @waku/run logs\n"})}),"\n",(0,s.jsx)(n.h3,{id:"check-node-health",children:"Check Node Health"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"# Node 1\ncurl http://127.0.0.1:8646/health\n\n# Node 2\ncurl http://127.0.0.1:8647/health\n"})}),"\n",(0,s.jsx)(n.h3,{id:"check-peer-connections",children:"Check Peer Connections"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"# Node 1 debug info\ncurl http://127.0.0.1:8646/debug/v1/info\n\n# Node 2 debug info\ncurl http://127.0.0.1:8647/debug/v1/info\n"})})]})}function u(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}}}]);