'spawn cd ENOENT

I am building a command line package. I am using the spawn method to execute cd command. Here's the code:

const cdChild = spawn('cd', [projectName])
cdChild.stdout.on('data', (data) => {
    console.log(data.toString())
})
cdChild.on('error', (err) => {
    console.log(err)
})

It gives the following error:

Error: spawn cd ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn cd',
  path: 'cd',
  spawnargs: [ 'bruh' ]
}
OS: Windows 10 21H1
Node: v16.13.0


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source