You have managed to mess up the file permissions in the NodeBB directory. You should always execute ./nodebb, npm, and git commands under the same unprivileged user, which means no sudo.
You will need to recursively chown the nodebb directory back over to whatever unprivileged user should own it.
What upgrade instructions are you trying to follow?