from subprocess import Popen, PIPE script = ''' console.log('hello world'); ''' p = Popen(['node'], stdin=PIPE, stdout=PIPE, stderr=PIPE) out, err = p.communicate(script.encode()) print(f'{out}\n{err}\n')