FSD Lab Manual
FSD Lab Manual
```javascript
const http = require('http');
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
```
```javascript
const express = require('express');
const bodyParser = require('body-parser');
app.listen(3000, () => {
console.log('Server running on port 3000');
});
```
```javascript
const fs = require('fs');
// Write to file
fs.writeFileSync('example.txt', 'Hello, World!');
// Append to file
fs.appendFileSync('example.txt', ' Appending this text.');
// Delete file
fs.unlinkSync('example.txt');
```
```javascript
const express = require('express');
const app = express();
app.listen(3000, () => {
console.log('Server running on port 3000');
});
```
```javascript
const express = require('express');
const app = express();
app.listen(3000, () => {
console.log('Food Delivery Server running on port 3000');
});
```
```javascript
const { MongoClient } = require('mongodb');
// Insert a document
await collection.insertOne({ name: 'John Doe' });
// Find a document
const results = await collection.findOne({ name: 'John Doe' });
console.log(results);
await client.close();
}
run().catch(console.error);
```
```javascript
async function crudOperations() {
// Assuming you have already established a connection to MongoDB
// Create
await collection.insertOne({ name: 'Jane Doe' });
// Read
const user = await collection.findOne({ name: 'Jane Doe' });
// Update
await collection.updateOne({ name: 'Jane Doe' }, { $set: { age: 30 } });
// Delete
await collection.deleteOne({ name: 'Jane Doe' });
}
```
```javascript
const count = await collection.countDocuments(); // Count
```html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body ng-controller="MyController">
<form ng-submit="submitForm()">
<input type="text" ng-model="name" placeholder="Enter your name" required>
<button type="submit">Submit</button>
</form>
<p>Hello, {{ name }}</p>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script>
angular.module('myApp', []).controller('MyController', function($scope) {
$scope.submitForm = function() {
alert("Form submitted!");
};
});
</script>
</html>
```
```html
<form name="jobForm" novalidate>
<input type="text" ng-model="jobTitle" name="jobTitle" required>
<span ng-show="jobForm.jobTitle.$touched && jobForm.jobTitle.$invalid">Job title is
required.</span>
```javascript
app.controller('MyController', function($scope, $http) {
$http.get('employee.json').then(function(response) {
$scope.employees = response.data;
});
});
```
The implementation may require a backend API using Express, like the one outlined previously for
login, combined with an AngularJS front end to manage students.
```javascript
import React, { useState } from 'react';
function Calculator() {
const [result, setResult] = useState("");
return (
<div>
<input type="text" value={result} readOnly />
<button onClick={() => calculate('1')}>1</button>
<button onClick={() => calculate('2')}>2</button>
<button onClick={() => setResult(eval(result))}>=</button>
</div>
);
}
```javascript
import React, { useState } from 'react';
function VotingApp() {
const [votes, setVotes] = useState(0);
return (
<div>
<h1>Votes: {votes}</h1>
<button onClick={vote}>Vote</button>
</div>
);
}
```javascript
import React, { useState } from 'react';
function LeaveManagement() {
const [leaveType, setLeaveType] = useState('Casual Leave');
const [days, setDays] = useState(10); // Available Days
return (
<div>
<h2>Available Leave Days: {days}</h2>
<select value={leaveType} onChange={(e) => setLeaveType(e.target.value)}>
<option value="Casual Leave">Casual Leave</option>
<option value="Medical Leave">Medical Leave</option>
</select>
<button onClick={applyLeave}>Apply Leave</button>
</div>
);
}
```javascript
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
function App() {
return (
<Router>
<Switch>
<Route path="/products" component={Products} />
<Route path="/checkout" component={Checkout} />
</Switch>
</Router>
);
}
```
This will be similar to the food delivery concept but with additional pages for registration and product
viewing.
```javascript
function App() {
return (
<Router>
<Route path="/register" component={Registration} />
<Route path="/login" component={Login} />
<Route path="/products" component={Products} />
</Router>
);
}
```