Verify that npm is already installed by running the command npm -v on the terminal. If...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Verify that npm is already installed by running the command npm -v on the terminal. If npm is installed, then the version number will be displayed. Otherwise install npm from the Nodejs.org site Create a new folder called mysql Project and make it your working directory. Use the following command to initialize your project directory and create the package.json file. Use -y option to accept the defaults. npm init -y The init command usually invokes a set of questions to customize the package.json to your project. For our purpose we will accept the default values. Install the MySQL driver using the following command npm install mysql2 Note that we will use mysq12 instead of mysql due to an error received when using mysql. If curious, you can learn more about this error here In Vscode open the mysql Project folder and create the file connect.js. In connect.js write the following code. For the user and password write your username and password that you have chosen when setting up the MySQL server 1 2 3 4 567 8 9 10 11 12 13 14 15 //import the mysql2 module const mysql = require ('mysql2'); // initialize the connection object const mysqlConnect = mysql.createConnection({ host "localhost", user : "root", password: "adminPass", }); //Check the status of the connection mysqlConnect.connect((err) =>{ }); if (err) throw err; console.log("Connected!!") Save the file and run it using node connect.js. You should get the following output Connected!! To close a database connection gracefully, you call the end () method on the connection object. The end () method ensures that all remaining queries are always executed before the database connection is closed. Stop the script and add the following code to connect.is, mysqlConnect.end(function(err) { if (err) { $9 $4 $4 $4 $4 $4 57 } return console.log('error: + err.message); console.log("Closing the database connection...'); }); Save the file and run it again using node connect.js. You should get the following output Connected!! Activity Creating a Database in Nodejs In this Activity we will write the code for creating and managing a database from within a .js file executed on the Nodejs platform. You will be given guidance on how to write the code. However, you will be required to fill in the SQL commands relevant to each step. This activity is based on the online MySQL NodeJS tutorial. The database used in this activity is like the database created in Programming Activity 4. However, S_code and C_code are assigned by the user rather than by the DB engine. Closing the database connection... Submit your file to BB. Student Course S code C code SI C4 $2 C4 S8 C4 $3 $3 $3 $5 $5 $5 $6 $6 $6 $9 $9 CI C3 C5 CI C3 C5 CI C3 C5 CI C3 C5 CI C2 C3 C4 C5 C2 grade A B A A A A B A с C C B A B B A A B B A B Course C code C_name convenience. 3. Creating the Database: CI C2 C3 C4 CS Student S code S_name S_year $1 Anne 1st S2 Bob 1st Peter 2nd Tracy 3rd Tom 2nd S3 S4 S5 S6 S7 S8 $9 Database Modelling Distributed Systems Software Engineering Programming Languages Compilers EERRE Paul 2nd Smith 3rd 1st Mary John 2nd C book Introduction to Databases Advanced Systems Software Engineering Applications From Fortran to Java Introduction to Compilers Cyear 2nd 3rd 2nd 1st 2nd 1. Copy connect.js to connectl.js. 2. Change the name of the database connection object to a shorter name, such as db, for To manage a database from within a .js file, you need first to create a string that holds the SQL command and then call the query() method on the database connection object passing to it as a parameter the string that holds the SQL command and a callback function. a. Declare the string variable sql to hold the SQL command for creating a new database called Stud Tracking. let sql = "Fill in SQL COMMAND TO CREATE A DATABASE"; b. Pass sql and a call back function to the query () function db.query(sql, (err) => { if(err) throw err; console.log('Database Created'); }); c. Save connect1.js and execute it from the command prompt. d. Check that the new database has been created on the MySQL server. e. If you execute connect1.js again you will receive the following error that indicates that the database already exists. Error: Can't create database 'StudTrack'; database exists f. To avoid this error, add the clause IF NOT EXISTS to the sql command creating the database. Check the MySQL Cheat sheet for the correct syntax. Submit your file to BB. Creating the Database Table: The code for creating the tables in the database will be written after the code for creating the Database developed in the previous step and before the call to the end (). a. Creating the Student Table: assign the string variable sql to hold the SQL command for creating the student table. Note that for the S-code, it is assumed that the student code will be composed of at most 5 characters provided by the user. sql = "Fill in SQL COMMAND TO CREATE Student TABLE"; b. Call the query() function again passing to it the SQL command stored in sql and a callback function as before. Note that you might receive the following errors: i. Error: No database selected. (Hint: you need to specify the database used. One solution is to precede the table name with the database name or check the online manual for another solution) ii. Error: Table 'students' already exists. (Hint: the solution is similar to that used for the database above. Check the online manual for syntax) c. Run your script twice to ensure that you handled all errors d. Create the Course table applying similar steps as before. e. Create StudentCourse table applying similar steps as before. Verify that npm is already installed by running the command npm -v on the terminal. If npm is installed, then the version number will be displayed. Otherwise install npm from the Nodejs.org site Create a new folder called mysql Project and make it your working directory. Use the following command to initialize your project directory and create the package.json file. Use -y option to accept the defaults. npm init -y The init command usually invokes a set of questions to customize the package.json to your project. For our purpose we will accept the default values. Install the MySQL driver using the following command npm install mysql2 Note that we will use mysq12 instead of mysql due to an error received when using mysql. If curious, you can learn more about this error here In Vscode open the mysql Project folder and create the file connect.js. In connect.js write the following code. For the user and password write your username and password that you have chosen when setting up the MySQL server 1 2 3 4 567 8 9 10 11 12 13 14 15 //import the mysql2 module const mysql = require ('mysql2'); // initialize the connection object const mysqlConnect = mysql.createConnection({ host "localhost", user : "root", password: "adminPass", }); //Check the status of the connection mysqlConnect.connect((err) =>{ }); if (err) throw err; console.log("Connected!!") Save the file and run it using node connect.js. You should get the following output Connected!! To close a database connection gracefully, you call the end () method on the connection object. The end () method ensures that all remaining queries are always executed before the database connection is closed. Stop the script and add the following code to connect.is, mysqlConnect.end(function(err) { if (err) { $9 $4 $4 $4 $4 $4 57 } return console.log('error: + err.message); console.log("Closing the database connection...'); }); Save the file and run it again using node connect.js. You should get the following output Connected!! Activity Creating a Database in Nodejs In this Activity we will write the code for creating and managing a database from within a .js file executed on the Nodejs platform. You will be given guidance on how to write the code. However, you will be required to fill in the SQL commands relevant to each step. This activity is based on the online MySQL NodeJS tutorial. The database used in this activity is like the database created in Programming Activity 4. However, S_code and C_code are assigned by the user rather than by the DB engine. Closing the database connection... Submit your file to BB. Student Course S code C code SI C4 $2 C4 S8 C4 $3 $3 $3 $5 $5 $5 $6 $6 $6 $9 $9 CI C3 C5 CI C3 C5 CI C3 C5 CI C3 C5 CI C2 C3 C4 C5 C2 grade A B A A A A B A с C C B A B B A A B B A B Course C code C_name convenience. 3. Creating the Database: CI C2 C3 C4 CS Student S code S_name S_year $1 Anne 1st S2 Bob 1st Peter 2nd Tracy 3rd Tom 2nd S3 S4 S5 S6 S7 S8 $9 Database Modelling Distributed Systems Software Engineering Programming Languages Compilers EERRE Paul 2nd Smith 3rd 1st Mary John 2nd C book Introduction to Databases Advanced Systems Software Engineering Applications From Fortran to Java Introduction to Compilers Cyear 2nd 3rd 2nd 1st 2nd 1. Copy connect.js to connectl.js. 2. Change the name of the database connection object to a shorter name, such as db, for To manage a database from within a .js file, you need first to create a string that holds the SQL command and then call the query() method on the database connection object passing to it as a parameter the string that holds the SQL command and a callback function. a. Declare the string variable sql to hold the SQL command for creating a new database called Stud Tracking. let sql = "Fill in SQL COMMAND TO CREATE A DATABASE"; b. Pass sql and a call back function to the query () function db.query(sql, (err) => { if(err) throw err; console.log('Database Created'); }); c. Save connect1.js and execute it from the command prompt. d. Check that the new database has been created on the MySQL server. e. If you execute connect1.js again you will receive the following error that indicates that the database already exists. Error: Can't create database 'StudTrack'; database exists f. To avoid this error, add the clause IF NOT EXISTS to the sql command creating the database. Check the MySQL Cheat sheet for the correct syntax. Submit your file to BB. Creating the Database Table: The code for creating the tables in the database will be written after the code for creating the Database developed in the previous step and before the call to the end (). a. Creating the Student Table: assign the string variable sql to hold the SQL command for creating the student table. Note that for the S-code, it is assumed that the student code will be composed of at most 5 characters provided by the user. sql = "Fill in SQL COMMAND TO CREATE Student TABLE"; b. Call the query() function again passing to it the SQL command stored in sql and a callback function as before. Note that you might receive the following errors: i. Error: No database selected. (Hint: you need to specify the database used. One solution is to precede the table name with the database name or check the online manual for another solution) ii. Error: Table 'students' already exists. (Hint: the solution is similar to that used for the database above. Check the online manual for syntax) c. Run your script twice to ensure that you handled all errors d. Create the Course table applying similar steps as before. e. Create StudentCourse table applying similar steps as before.
Expert Answer:
Answer rating: 100% (QA)
Answer Steps to follow to achieve target according to question Step 1 Verify that npm is already ins... View the full answer
Related Book For
Accounting Information Systems
ISBN: 978-0133428537
13th edition
Authors: Marshall B. Romney, Paul J. Steinbart
Posted Date:
Students also viewed these databases questions
-
Refer to the American Journal of Archaeology (Jan. 2014) study of sword shaft graves in ancient Greece, Exercise 2.37 (p. 50). The number of sword shafts buried at each of 13 recently discovered...
-
"How do you see the future of one of the largest iBuyers, Opendoor, unfolding in the next 3-5 years? Do you expect them to SURVIVE with their current model? Will it have to pivot somehow to get more...
-
For the Dupit Corp. case study introduced in Section 11.4, the management science team was able to apply a variety of queueing models by making the following simplifying approximation. Except for the...
-
Prepare a statement of cash flows in proper form using the inflows and outflows from questions 4-15. Assume net income (earnings after taxes) from the 2018 income statement was $10,628, and $5,000 in...
-
As in Ex. 154, design a cylindrical worm-gear mesh to connect a squirrel-cage induction motor to a liquid agitator. The motor speed is 1125 rev/min, and the velocity ratio is to be 10:1. The output...
-
Kohler Clothiers manufactures women's business suits. The company uses a standard cost accounting system. In March 2012, 15,700 suits were made. The following standard and actual cost data applied to...
-
Earth Trilogy Ltd has prepared the following fixed budget performance report. Required (a) Prepare a flexible budget performance report for the actual level of activity. (b) Comment on the...
-
Batch processes are often used in chemical and pharmaceutical operations to achieve a desired chemical composition for the final product and typically involve a transient heating operation to take...
-
Glendale Pediatrics is a nine-clinician pediatric group practice. The practice serves a largely middle-class suburban population and prides itself on the provision of preventive services. One of the...
-
Costello Company has several divisions. The controller, Sarah James, prepares monthly segment reports for each division. Each division manager is evaluated annually, based largely on the segment...
-
Bowflexs television ads say you can get a fitness machine that sells for $999 for $33 a month for 36 months. What rate of interest are you paying on this Bowflex loan?
-
Consider a previously closed economy that opens up to international trade. Reference the dynamic aggregate demand-aggregate supply framework below to describe a situation where this would lead to...
-
Zachary Concrete Company pours concrete slabs for single - family dwellings. Lancing Construction Company, which operates outside Zachary s normal sales territory, asks Zachary to pour 5 1 slabs for...
-
5. (5 pts) Briefly explain, from a thermal perspective why there is an "optimal" spacing between the inner and outer glass panes in double-paned windows. 6. (5 pts) Consider a double pane window...
-
Use the following selected data from Business Solutions's income statement for the three months ended March 31, 2022, and from its March 31, 2022, balance sheet to complete the requirements. Computer...
-
Pumps can be set in series or in parallel depending on the desired output. If the flow rate needs to be increased, the pumps are put in parallel. On the other hand, if the head has to be increased,...
-
Match each form of unemployment with an example. Note that every item may not have a match. Drag each item on the left to its matching item on the right. Note that every item may not have a match,...
-
Respond to the ethical judgments required based on the following scenarios. Scenario 1. Assume you have collected a sample using MUS and that you have evaluated that sample to calculate a total...
-
The Computer Warehouse sells computer hardware, software, and supplies (such as paper). Individual customers just walk into the store, select merchandise, and must pay for their purchases in full...
-
Tralor Corporation manufactures and sells several different lines of small electric components. Its internal audit department completed an audit of its expenditure processes. Part of the audit...
-
What kinds of documents are most likely to be turnaround documents? Do an Internet search to find the answer and to find example turnaround documents.
-
Assume a gain margin of 20 dB and a plant with a nominal gain of 50/sec. Assume also that the minimum GM of the system is specified to 10 dB. To what maximum value of gain can the plant climb under...
-
Name three benefits of using software R/D conversion compared with hardware R/D converters.
-
Correcting for reversal error correction and deadband compensation are special cases of what general technique?
Study smarter with the SolutionInn App