Reading from serial. Works in sample-js file, but when running in node-red serial port gets closed

Not clear what pi you are using, however have a look at this.