5. Let the sequence of positive numbers $\left\{a_{n}\right\}$ satisfy
$$
\begin{array}{l}
a_{1}=\sqrt{2}-1, \\
a_{n+1}=\frac{2 n+1}{S_{n}+S_{n+1}+2}(n=1,2, \cdots),
\end{array}
$$

where $S_{n}$ is the sum of the first $n$ terms of $a_{n}$. Then the general term formula of the sequence is $\qquad$
5. $a_{n}=\sqrt{n^{2}+1}-\sqrt{(n-1)^{2}+1}$.

By $a_{n+1}=S_{n+1}-S_{n}=\left(S_{n+1}+1\right)-\left(S_{n}+1\right)$
$\Rightarrow\left(S_{n+1}+1\right)-\left(S_{n}+1\right)=\frac{2 n+1}{\left(S_{n+1}+1\right)+\left(S_{n}+1\right)}$
$\Rightarrow\left(S_{n+1}+1\right)^{2}-\left(S_{n}+1\right)^{2}=(n+1)^{2}-n^{2}$.
Let $T_{n}=\left(S_{n}+1\right)^{2}-n^{2}$. Then $T_{n+1}=T_{n}$, that is,
$\left\{T_{n}\right\}$ is a constant sequence.
It is easy to see that $T_{1}=1$.
Therefore, $\left(S_{n}+1\right)^{2}-n^{2}=1$
$\Rightarrow S_{n}=\sqrt{n^{2}+1}-1(n=1,2, \cdots)$.
Notice that, when $n=0$, $S_{0}=0$ also satisfies.
Hence $a_{n}=S_{n}-S_{n-1}=\sqrt{n^{2}+1}-\sqrt{(n-1)^{2}+1}$.