Setup: Run the App Without LND
Last updated
Last updated
Before we begin adding Lightning Network integration, let’s first get the app running on your computer.
Checkout the initial-app branch and start the app:
Open your browser to http://localhost:3000 if it doesn’t open automatically.
If all went well with your development environment setup, you should see the initial screen below:
Click on the Create a Post button to go to the Create screen.
Fill in some info for the Username, Title, and Content fields, then click on the Submit button. You will be redirected back to the screen displaying the list of posts.
Add a couple more posts, just to have some data to play with.
Click on the Upvote button on a post to see the votes counter increment and the posts reorder based on which has the highest votes.
The app makes use of WebSockets to update the UI in real-time when posts are created and upvoted on the backend. To see this in action, open a second browser window side-by-side with the first window. Create a new post on the left to see it automatically appear on the right. Upvote a post on the right to see it increment and reorder on the left automatically.
This application is split into two parts, the backend API server and the frontend browser-based UI.
The backend API server stores the posts data in a centralized location for multiple clients to query. It is built using the NodeJS platform for code execution and expressjs web framework to handle API routing of requests and responses.
The backend does not use a traditional database to try to keep the sample application simple. Instead, it keeps all of the posts & nodes data in memory while the server is running. It also persists the data to a JSON file in plain text on disk whenever it’s modified. This was done to make development easier. The backend server will need to restart often when making code changes and we would lose all of our data after each restart. In a real world application, you should use a production level database.
The structure of the files in the backend folder are:
The frontend web client displays the posts in a browser-based UI to allow users to interact with the app. It is built using ReactJS for rendering the HTML views and mobx for client state management.
The data flow in the frontend uses a layered approach to maintain a separation of concerns and make it easier to reason about. All of the application logic is done in the mobx store. Only it can make use of the API Wrapper functions. The React components are kept very light weight with just the forms containing local component state for input fields.
The structure of the files in the src folder are:
Now that you have a basic understanding of the initial application that we are working with, let’s start adding some Lightning Network functionality to our app.