contentcraft/index.js

46 lines
No EOL
1.4 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const marked = require('marked'); //note: this is used in other files
require('dotenv').config(); // Load environment variables from .env file
const express = require('express');
const app = express();
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 {
// Create a new function and execute it
const func = new Function(data);
func(); // Call the function
} catch (e) {
console.error(`Error executing ${file}:`, e);
}
});
});
});
app.listen(PORT, () => {
console.log(`Website server is running on port ${PORT}`);
});