Upload a newer version of document from within Alfresco repository

Create Document, Make it Versionable, Modify It Creates a document, makes it versionable, checks it out, modifies the content of the working copy, checks it in again and then repeats the process but checks in the document with a version history note and as a major version increment:

// create file, make it versionable
var doc = userhome.createFile('checkmeout.txt');
doc.addAspect('cm:versionable');
doc.content = 'original text';

// check it out and update content on the working copy
var workingCopy = doc.checkout();
workingCopy.content = 'updated text 1';

// check it in
doc = workingCopy.checkin();

// check it out again
workingCopy = doc.checkout();
workingCopy.content = 'updated text 2';

// check it in again, but with a version history note and as major version increment
doc = workingCopy.checkin('a history note', true);

You can take reference from below javascript api link https://hub.alfresco.com/t5/alfresco-content-services-hub/javascript-api-cookbook/ba-p/293260