Professional Documents
Culture Documents
WT Asssignment 7
WT Asssignment 7
function readFile() {
const filePath = document.getElementById('filePath').value;
fetch(`/read?path=${filePath}`)
.then(response => response.text())
.then(data => {
document.getElementById('output').innerText = data;
});
}
function appendFile() {
const filePath = document.getElementById('filePath').value;
const content = document.getElementById('content').value;
fetch(`/append?path=${filePath}&content=${content}`, {
method: 'POST'
})
.then(response => response.text())
.then(data => {
document.getElementById('output').innerText = data;
});
}
function copyFile() {
const sourcePath = document.getElementById('sourcePath').value;
const destinationPath = document.getElementById('destinationPath').value;
fetch(`/copy?source=${sourcePath}&destination=${destinationPath}`)
.then(response => response.text())
.then(data => {
document.getElementById('output').innerText = data;
});
}
function moveFile() {
const sourcePath = document.getElementById('sourcePath').value;
const destinationPath = document.getElementById('destinationPath').value;
fetch(`/move?oldPath=${sourcePath}&newPath=${destinationPath}`)
.then(response => response.text())
.then(data => {
document.getElementById('output').innerText = data;
});
}
function deleteFile() {
const filePath = document.getElementById('filePath').value;
fetch(`/delete?path=${filePath}`)
.then(response => response.text())
.then(data => {
document.getElementById('output').innerText = data;
});
}
function renameFile() {
const oldPath = document.getElementById('oldPath').value;
const newPath = document.getElementById('newPath').value;
fetch(`/rename?oldPath=${oldPath}&newPath=${newPath}`)
.then(response => response.text())
.then(data => {
document.getElementById('output').innerText = data;
});
}
Server.js
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3000;
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
Index.htm
l<!DOCTYPE html>
<html>
<head>
<title>Node.js File Handling Operations</title>
</head>
<body>
<h2>File Handling Operations</h2>
<p id="output"></p>
<script src="script.js"></script>
</body>
</html>
OUTPUT
File Operations
Reading