How does node enter the specified directory and execute the shell command?

I want to execute npm run build, in the specified directory through an API written by node, but the result reports an error. The reason is the directory where the npm run build is executed or the directory where the file is located. How to achieve the desired results?

process.exec("cd ", function (error, stdout, stderr) {
    process.exec("npm run build", function(error, stdout, stderr) {
        
    });
})
Mar.25,2021

in addition to the upstairs method, you can also process.chdir


1. You can use shell.js


process.exec('npm run build',{ cwd:'you script path' }, function(error, stdout, stderr) {
        
    });
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e55c6e-45357.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e55c6e-45357.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?