Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- function runJSFile(filePath) {
- fs.readFile(filePath, 'utf8', (err, data) => {
- if (err) {
- console.error('Error reading the file:', err);
- } else {
- try {
- // Create the function object without using eval
- const jsFunction = new Function(data);
- // Call the function to execute the JavaScript code
- jsFunction();
- } catch (e) {
- console.error('Error executing JavaScript code:', e);
- }
- }
- });
- }
- // Replace 'path/to/your/javascript_file.js' with the actual path to your JavaScript file
- runJSFile('path/to/your/javascript_file.js');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement