WF
WF
*Set 2:*
Modal View Template is not a standard term. However, in Django, the architecture is based on the
Model-View-Controller (MVC) pattern. Django calls it Model-View-Template (MVT), where:
- *Core Modules:* These are built-in modules that come with Node.js, such as fs (File System) and
http (HTTP).
- *Local Modules:* Created by users for specific applications. They are files created by the user and
used within the application.
- *Third-Party Modules:* External modules that are not part of the Node.js core and can be
installed using NPM (Node Package Manager).
- buffer.write(string[, offset][, length][, encoding]): Writes a string to the buffer with an optional
offset, length, and encoding.
- buffer.toString([encoding][, start][, end]): Decodes the buffer data to a string with an optional
encoding, start, and end.
Django REST Framework is a powerful toolkit for building Web APIs in Django applications. It adds
functionality to Django for handling web API requests and responses. It includes features like
serialization, authentication, viewsets, and more.
*Set 3:*
javascript
function fetchData(callback) {
setTimeout(() => {
console.log('Data Fetched!');
callback();
}, 2000);
function processData() {
console.log('Data Processed!');
fetchData(processData);
The following code creates a simple HTTP server using the built-in http module in Node.js:
javascript
res.end('Hello, World!');
});
});
3. *Array in JavaScript:*
An array in JavaScript is a data structure that stores a collection of elements. It can hold values of
different data types. Example:
javascript
*Set 4:*
In Django, views.py contains Python functions (views) that handle requests and return responses.
These views define the logic for processing requests and rendering templates. Example:
python
def index(request):
- *Traditional Web Server Model:* Synchronous, handles one request at a time. Each request
creates a new thread or process.
- *Node.js Process Model:* Asynchronous, handles multiple requests simultaneously using a single-
threaded event loop. Non-blocking I/O operations.
NPM is the package manager for Node.js. It is used to install, manage, and share packages
(libraries) in Node.js applications. NPM simplifies the process of adding external functionality to a
project.
*Set 5:*
The export statement is used to make functions or variables available outside a module. Example:
javascript
// modules.js
module.exports = { currentDate };
2. *Express.js Explanation:*
Express.js is a web application framework for Node.js. It simplifies the process of building robust
web applications and APIs. Key features include routing, middleware support, and a modular
structure. It is widely used for its simplicity and flexibility.
REPL is an interactive programming environment for Node.js. It allows users to enter and execute
commands in real-time. It stands for Read-Eval-Print Loop, where each command is read, evaluated,
and the result is printed.
*Set 6:*
The following code creates a Node.js file that converts the output "Hello World!" into uppercase
letters:
javascript
console.log(text.toUpperCase());
- req: Represents the HTTP request and contains properties like req.params and req.query.
- res: Represents the HTTP response and includes methods like res.send() to send a response.
javascript
// mymodule.js
module.exports = myFunction;
In another file, you can use require('./mymodule') to access the function globally.
*Set 7:*
The following Node.js script selects all records from the student table using the mysql module:
javascript
host: 'localhost',
user: 'username',
password: 'password',
database: 'database',
});
connection.connect();
console.log(results);
});
connection.end();
The fs.readFile() method in Node.js is used to read the contents of a file asynchronously. It takes a
filename, an optional encoding, and a callback function. Example:
javascript
const fs = require('fs');
console.log(data);
});
Create a Node.js module in a file named modules.js with a function to return today's date and
time:
javascript
// modules.js
module.exports = { getCurrentDateTime };