Question

In: Computer Science

Using Node.js with Express, show how you would create the following routes, using these URL's, as...

Using Node.js with Express, show how you would create the following routes, using these URL's, as examples:

~ http:#localhost:4200/books/isbn/978123487999/author

This URL will return an author's full name from array of names, mapped by ISBN.

~ http:〃localhost:4200/books

This returns all the books (just the book names) from the database.

Solutions

Expert Solution

If you have any problem with the code feel free to comment.

Program

const express = require('express');

const app = new express();

// http:#localhost:4200/books/isbn/978123487999/author
//sending author name using isbn
app.get('/books/isbn/:isbn/author', (req, res) => {
        const isbn = req.params.isbn;
        let author;
        //searching for author
        for (let i = 0; i < authorData.length; i++) {
                if (isbn == authorData[i].isbn) {
                        author = authorData[i].author;
                        break;
                }
        }
        res.send(author);
});

//return all book names from the database
app.get('/books', (req, res) => {
        res.send(booksData);
});

//starting the server
const server = app.listen(4200, () => {
        console.log('server has started');
});
//dummy database data for testing
const authorData = [
        {
                isbn: 978123487999,
                author: 'Harper Lee',
        },
        {
                isbn: 124536987456,
                author: 'F. Scott Fitzgerald',
        },
        {
                isbn: 523698745156,
                author: 'J. D. Salinger',
        },
        {
                isbn: 635124102359,
                author: 'Charlotte Brontë',
        },
];

const booksData = [
        { name: 'To Kill a Mockingbird' },
        { name: 'The Great Gatsby' },
        { name: 'The Catcher in the Rye' },
        { name: 'Jane Eyre' },
];

Output


Related Solutions

Using Node.js, show how you would read a file and and write out its contents to...
Using Node.js, show how you would read a file and and write out its contents to a new file in reverse order. As an example, if the source file had: Roses are red, Violets are blue. If the Trump administration continues to lose cabinet members, I will not be sad. Boo hoo hoo. The destination file would have: I will not be sad. Boo hoo hoo. If the Trump administration continues to lose cabinet members, Violets are blue. Roses are...
Write a simple javascript program using express and node.js to create a simple webpage that can...
Write a simple javascript program using express and node.js to create a simple webpage that can lead to other pages within the program. if possible, Comment everything out so I could understand how every things works.  But basically, server should be hosted on localhost:8000 and should have a simple starting page. Maybe a welcome message, with at least two "links" that goes to a "homepage" and then a "exit" page.
Using node.js, create the following tasks. 1. Set up a server and HTML file server as...
Using node.js, create the following tasks. 1. Set up a server and HTML file server as shown in the videos. Once you have it successfully running, make the following adjustments A. When a 404 error (file not found) occurs, display a funny message about the file missing and/or did you forget how to type? B. If the user enters a request for the home page (index.html) then: Display an index.html page you have created which includes your name, course number,...
Using Node.js as a Webserver 1. How do you modify a webserver.js code to include your...
Using Node.js as a Webserver 1. How do you modify a webserver.js code to include your name and date? Please include code. 2. Create a MongoDB database for the following group that includes member names and contact information and Include code: Gourp member exapmples: Pete 912-555-6666; Sam 912-111-3333; Mary 678-111-1111; and April 912-690-1111
In a sale of goods, which of the following would, LEAST LIKELY, create an EXPRESS WARRANTY...
In a sale of goods, which of the following would, LEAST LIKELY, create an EXPRESS WARRANTY under Section 2-313 of the U.C.C.:
Can you please show how you would solve the following using excel? Step by Step? Kaelea,...
Can you please show how you would solve the following using excel? Step by Step? Kaelea, Inc., has no debt outstanding and a total market value of $117,000. Earnings before interest and taxes, EBIT, are projected to be $8,300 if economic conditions are normal. If there is strong expansion in the economy, then EBIT will be 23 percent higher. If there is a recession, then EBIT will be 32 percent lower. The company is considering a $41,700 debt issue with...
Create a simple product or service that you would like to sell. Present the following (show...
Create a simple product or service that you would like to sell. Present the following (show your calculations) in a written document: Cost per unit—variable costs per unit only, and fixed costs with an assumed level of production. Sales price per unit Selling and Administrative costs-- variable costs per unit only, and fixed costs with the same assumed level of production that was used in #1. Breakeven point in units and in dollars. CVP income statement using an assumed level...
Create a simple product or service that you would like to sell. Present the following (show...
Create a simple product or service that you would like to sell. Present the following (show your calculations) in a written document: Cost per unit—variable costs per unit only, and fixed costs with an assumed level of production. Sales price per unit Selling and Administrative costs-- variable costs per unit only, and fixed costs with the same assumed level of production that was used in #1. Breakeven point in units and in dollars. CVP income statement using an assumed level...
Respond to the following in a minimum of 175 words: Describe how you would create a...
Respond to the following in a minimum of 175 words: Describe how you would create a Java program for creating a lottery program using arrays and methods. If the user wants to purchase 5 lottery tickets, which looping structure would you use and why? Include the necessary code and code descriptions.
Using one financial ratio discussed, show how you would use it to analyze the financial position...
Using one financial ratio discussed, show how you would use it to analyze the financial position of a health care facility or department. Include current benchmarks in your discussion.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT