Overview of the project

The project reuses some of the code from the application we built in Chapter 7Creating an Application from Scratch (Cook the Books) to demonstrate how Node.js can be used with WebAssembly. The code for this section is located in the /chapter-09-node/server-example folder in the learn-webassembly repository. We're going to review portions of the application directly applicable to Node.js. The following structure represents the file structure for the project:

├── /lib
│ └── main.c
├── /src
| ├── Transaction.js
| ├── /assets
| │ ├── db.json
| │ ├── main.wasm
| │ └── memory.wasm
| ├── assign-routes.js
| ├── index.js
| └── load-assets.js
├── package.json
├── package-lock.json
└── requests.js

With regard to dependencies, the application uses the express and body-parser libraries to set up routes and parse JSON from the body of requests. For data management, it uses lowdb, a library that provides methods for reading and updating a JSON file. The JSON file is located in /src/assets/db.json and contains data that was slightly modified from the Cook the Books dataset. We're using nodemon to watch for changes in the /src folder and reload the application automatically. We're using rimraf to manage file deletion. The library is included as a dependency in the event that you didn't install it globally in Chapter 3Setting Up a Development Environment. Finally, the node-fetch library allows us to use the fetch API to make HTTP requests when testing the application.

To simplify functionality in both the JavaScript and C files, the rawAmount and cookedAmount fields were replaced with a single amount field, and the category field is now categoryId, which maps to a categories array in db.json.
..................Content has been hidden....................

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