Reading: This page describes how to set up PuTTY to, among other things, create SSH tunnels.
For this lab you will be creating a simple Node.js project that uses the Express framework to create a simple web server. This server will interact with a MongoDB database to store and retrieve information about variable stars.
In the Iapetus project, create a folder named backend that is a sibling to the frontend folder you've been working with so far. Inside that folder, execute the following commands to initialize a Node.js project and to install the Express.js framework.
$ npm init -y $ npm install express $ npm install mongodb $ npm install cors
The -y option causes npm to use default values for the initial settings. You can edit the generated file package.json later if you want. The express package is Express, a framework for using the HTTP protocol in JavaScript. The mongodb package is the driver for the MongoDB database server. The cors package is a middleware layer that implements the Cross Origin Resource Sharing protocol needed to allow your React application from one origin to access your API server at a different origin.
Run the app.mjs sample application in Node.js using the command:
$ node app.mjs
Using Postman (or a web browser) verify that it works as expected.
Next run the mongoDemo.mjs sample application in Node.js using the command:
$ node mongoDemo.mjs
Using Postman (or a web browser) verify that it works as expected.
Start by modifying mongoDemo.mjs so it accepts the name of a constellation in the GET URL and executes the query for that constellation. For example, a GET request of:
http://localhost:3000/api/stars/Del
This should return information about all variable stars in Delphinus (a minor constellation in the North American summer sky). You can use Compass to verify the results.
Next, modify the Iapetus web application (start with your solution to Lab #8) so that when it renders the component on the left side of the screen, it executes the Delphinus query and displays the results in some suitable manner (e.g., a table).
Zip together your modified mongoDemo.mjs and the main application file of your React application and submit the archive to Canvas.
Last Revised: 2024-11-22
© Copyright 2024 by Peter Chapin <peter.chapin@vermontstate.edu>