Nord Js
Nord Js
a) What is the command to initialize node package manager (NPM)? Write its syntax.
Command:
sh
CopyEdit
npm init
b) What is REPL?
REPL stands for Read-Eval-Print Loop. It is an interactive shell in Node.js that allows users to
execute JavaScript code and see immediate results.
sh
CopyEdit
npm install express
sh
CopyEdit
h) Write down steps to handle HTTP requests while creating a web server using Node.js.
2. Single Programming Language – Uses JavaScript for both client and server-side
development.
a) Write a Program to update table records using Node.js and MySQL database.
javascript
CopyEdit
host: "localhost",
user: "root",
password: "",
database: "mydatabase"
});
connection.connect();
const sql = "UPDATE users SET name = 'John Doe' WHERE id = 1";
console.log("Record Updated!");
});
connection.end();
• Event loop continuously checks for pending tasks and executes callbacks.
3. Once the file is read, it sends the response back to the client.
javascript
CopyEdit
event.addListener('greet', () => {
event.emit('greet');
javascript
CopyEdit
host: "localhost",
user: "root",
password: "",
database: "mydatabase"
});
connection.connect();
console.log("Record Deleted!");
});
connection.end();
d) How do you install Packages locally using NPM? Explain with an example.
sh
CopyEdit
a) Write a Program to use SQL SELECT query to show data from a table using Node.js and
MySQL.
javascript
CopyEdit
host: "localhost",
user: "root",
password: "",
database: "mydatabase"
});
connection.connect();
console.log(results);
});
connection.end();
javascript
CopyEdit
const fs = require('fs');
});
javascript
CopyEdit
function factorial(n) {
if (n === 0) return 1;
javascript
CopyEdit
myEmitter.on('event', ()
4o