Apple - How to export/backup Notes in macOS in one go
You can use a third-party app called Notes Exporter to export all notes in one go. After granting access to the Notes data, the app exports each individual note as a separate text file in the location of your choosing.
The only limitation being that you'll need to re-import them one by one if you wish to use them on a new machine.
A better and much simpler approach, if you have the necessary storage space available would be to use iCloud to sync them to the new machine.
Note: No affiliation whatsoever to the developer of the app.
I copied the three files NoteStore.sqlite
, NoteStore.sqlite-shm
, and NoteStore.sqlite-wal
from ~/Library/Group Containers/group.com.apple.notes
of one Mac to another and my notes appear there now. All my notes were there, albeit half a day out of sync.
Another great third party app is Exporter. It exports as markdown and keeps both folders and attachments.