How to make Windows File Explorer appear in foreground every time called via Node.js

26 Views Asked by At

I'm calling Windows File Explorer through Node.js, and I want File Explorer to pop up in the foreground every time I call it, rather than remaining in the taskbar. How can I achieve this?

this is my code:

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors')
const { spawn } = require('child_process');

const app = express();
const corsOptions = {
    origin: '*',
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', 
    credentials: true, 
    optionsSuccessStatus: 204, 
    allowedHeaders: 'Content-Type,Authorization', 
};
app.use(cors(corsOptions));


app.use(bodyParser.json());

app.post('/asd', (req, res) => {
    var value1 = req.body.path;
    value1 = __dirname + '\\public\\' + value1;
    console.log(value1);
    const openExplorer = spawn('explorer', [value1]); openExplorer.on('error', (err) => { console.error(`打开文件资源管理器时发生错误: ${err}`); });



    res.json({
        message: '数据已接收并处理'
    });
});

const port = 3001;
app.listen(port, () => {
    console.log(`服务器运行在 http://localhost:${port}`);
});
0

There are 0 best solutions below