refactor the node chat js