Update a document from a document list

Hello, I have a list of documents that were uploaded in a previous step, in the next step I can update previously uploaded documents, I need a script idea of ​​how to replace an item in a document list with a new version, someone could help me?