contentcraft/index.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-10-13 10:52:27 -05:00
const fs = require('fs');
const path = require('path');
2024-10-13 11:30:51 -05:00
global.marked = require('marked'); //note: this is used in other files
2024-10-13 10:52:27 -05:00
require('dotenv').config(); // Load environment variables from .env file
2024-10-13 11:30:51 -05:00
2024-10-13 10:52:27 -05:00
const express = require('express');
2024-10-13 11:30:51 -05:00
global.app = express();
2024-10-13 10:52:27 -05:00
const PORT = process.env.PORT || 3000;
// Specify the folder containing the .js files
const folderPath = './addon-scripts'; // Change this to your folder path
// Read the directory
fs.readdir(folderPath, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
}
// Filter for .js files
const jsFiles = files.filter(file => path.extname(file) === '.js');
// Read and evaluate each .js file
jsFiles.forEach(file => {
const filePath = path.join(folderPath, file);
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file ${file}:`, err);
return;
}
try {
2024-10-13 11:30:51 -05:00
Function(data)()
2024-10-13 10:52:27 -05:00
} catch (e) {
console.error(`Error executing ${file}:`, e);
}
});
});
});
app.listen(PORT, () => {
console.log(`Website server is running on port ${PORT}`);
});