-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
34 lines (27 loc) · 734 Bytes
/
main.js
File metadata and controls
34 lines (27 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const vm = require('node:vm');
const fsp = require('node:fs').promises;
const metalog = require('metalog');
(async () => {
const logger = await metalog.openLog({
path: './log',
workerId: 1,
writeInterval: 5000,
writeBuffer: 64 * 1024,
keepDays: 5,
toStdout: [],
home: process.cwd(),
});
const context = {
module: {},
console: logger.console,
};
context.global = context;
const sandbox = vm.createContext(context);
const fileName = './application.js';
const src = await fsp.readFile(fileName, 'utf8');
const script = new vm.Script(`module.exports = () => {\n${src}\n};`);
const execute = script.runInNewContext(sandbox);
execute();
logger.close();
})();