In Azure Devops, you could use the Replace Tokens task from the Replace Tokens Extension.
Then you could add the task before the NPM pack task to replace the variable in Package.json -> Version field.
Here are the steps:
Package.Json file:
{
"name": "helloword",
"version": "0.0.#{SetNumber}#",
"description": "Hello World",
"main": "server.js",
...
}
Build Pipeline:
- Set Variables in Build Pipeline.

- Add the Replace Tokens task.

Note: Based on my test, npm package cannot support xx.x.x.x version format(npm publish) in azure devops. It can support the x.x.x-x.
So you can set buildnumber like this:$(Date:yyyyMMdd)-$(Rev:r)
.
Result:

Update:
You could try to use the Npm Version command.
npm version 0.0.$(build.buildnumber) --no-git-tag-version

Update2:
You could try to use the following powershell script to get the version field in the Package.json. Then update the patch number.
$filePath = "$(Build.sourcesdirectory)\package.json" #filepath
$Jsonfile= Get-Content $filePath | ConvertFrom-Json
$version = $Jsonfile.version
echo $version
$major,$minor,$build = $version.Split('.')
$build = "$(build.buildnumber)"
$bumpedVersion = $major,$minor,$build -join(".")
echo $bumpedVersion
Write-Host "##vso[task.setvariable variable=version]$bumpedVersion"
In Npm version, you could run the following command:
version $(version) --no-git-tag-version
