Advertisement
okpalan

eval_is_evil.js

Nov 9th, 2023 (edited)
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.63 KB | Source Code | 0 0
  1. const fs = require('fs');
  2.  
  3. function runJSFile(filePath) {
  4.   fs.readFile(filePath, 'utf8', (err, data) => {
  5.     if (err) {
  6.       console.error('Error reading the file:', err);
  7.     } else {
  8.       try {
  9.         // Create the function object without using eval
  10.         const jsFunction = new Function(data);
  11.         // Call the function to execute the JavaScript code
  12.         jsFunction();
  13.       } catch (e) {
  14.         console.error('Error executing JavaScript code:', e);
  15.       }
  16.     }
  17.   });
  18. }
  19.  
  20. // Replace 'path/to/your/javascript_file.js' with the actual path to your JavaScript file
  21. runJSFile('path/to/your/javascript_file.js');
Tags: Eval
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement