If $|f|$ is constant, so is $f$ for $f$ analytic on a domain $D$.
Let $f=u+iv$ be analytic on some domain $D$. Suppose the modulus is constant, so $u^2+v^2$ is constant. It follows that $$ u\frac{\partial u}{\partial x}+v\frac{\partial v}{\partial x}=0 $$ and $$ u\frac{\partial u}{\partial y}+v\frac{\partial v}{\partial y}=-u\frac{\partial v}{\partial x}+v\frac{\partial u}{\partial x}=0. $$ These imply that $\dfrac{\partial u}{\partial x}=0=\dfrac{\partial v}{\partial x}$ save when $u^2+v^2$ vanishes. This follows by considering the matrix equation $$ \left(\begin{array}{cc} u & v\\ v & -u\end{array}\right)\left(\begin{array}{c} \frac{\partial u}{\partial x}\\ \frac{\partial v}{\partial x}\end{array}\right)=0 $$ However, if $u^2+v^2=0$ at some point, then it is constantly $0$ in which case $f(z)$ vanishes identically.