Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,243 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
This web page has little node.js code isn't loaded properly on Azure however it is loaded full in Google Cloud.
{
"name": "myexpressapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"ejs": "~2.6.1",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"morgan": "~1.9.1"
}
}
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const PORT = 3000;
const FILES_DIR = path.join(__dirname, 'files');
app.use(express.static(__dirname));
app.get('/files', (req, res) => {
fs.readdir(FILES_DIR, (err, files) => {
if (err) {
return res.status(500).json({ error: 'Unable to read files directory' });
}
res.json(files);
});
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Files Directory</title>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 20px;
}
.file-list {
list-style: none;
padding: 0;
}
.file-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px;
margin: 8px 0;
background: #f8f9fa;
border-radius: 6px;
transition: all 0.2s;
}
.file-item:hover {
background: #e9ecef;
}
.download-btn {
background: #0366d6;
color: white;
padding: 8px 16px;
border-radius: 4px;
text-decoration: none;
}
</style>
</head>
<body>
<h1>Files Directory</h1>
<ul id="fileList" class="file-list"></ul>
<script>
async function fetchFiles() {
try {
const response = await fetch('/files');
const files = await response.json();
updateFileList(files);
} catch (error) {
console.error('Error fetching files:', error);
}
}
function updateFileList(files) {
const fileList = document.getElementById('fileList');
fileList.innerHTML = ''; // Clear existing list
files.forEach(file => {
const li = document.createElement('li');
li.className = 'file-item';
const fileName = document.createElement('span');
fileName.textContent = `📄 ${file}`;
const downloadLink = document.createElement('a');
downloadLink.href = `./files/${file}`;
downloadLink.className = 'download-btn';
downloadLink.textContent = 'Download';
downloadLink.setAttribute('download', '');
li.appendChild(fileName);
li.appendChild(downloadLink);
fileList.appendChild(li);
});
}
// Initial fetch
fetchFiles();
// Optionally, set an interval to refresh the file list periodically
setInterval(fetchFiles, 60000); // Refresh every 60 seconds
</script>
</body>
</html>