Replace 'write(buffer) ; end()' with 'end(buffer)'.