Starting and testing out the application

If you're making changes to the application or trying to fix a bug, you could use the watch script to watch for any changes to the contents of the /src folder and automatically restart the application if a change was made. Since we're just running and testing out the application, we can use the start command instead. In the terminal, ensure you're in the /server-example folder and run the following command:

npm start

You should see a message that says Server is running on port 3000. You're now able to send HTTP requests to the server. To test the application, open a new terminal instance within the server-example directory and run the following command:

node ./requests.js 1

This should log out the response body of the GET call to the /api/transactions endpoint. The requests.js file contains functionality that allows you to make requests to all of the available routes. The getFetchActionForId() function returns an object with an endpoint and options value, which corresponds to a route in the assign-routes.js file. The actionId is an arbitrary number to simplify testing and reduce the amount of typing for running commands. For example, you could run the following command:

node ./requests.js 5

It will log out the sum of all transactions for the Computer & Internet category. You can pass an additional argument to the node command if you want the total for a different category. To get the sum of all transactions in the Insurance category, run this command:

node ./requests.js 5 3

Try going through each of the requests (there are eight in total). If you make a request that adds, removes, or edits a transaction, you should see the changes in the /src/assets/db.json file. That's it for the Node.js example project. In the next section, we'll utilize Webpack to load and interact with a Wasm module.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset