If you are getting this error, you must ensure that the latest versions of node and NPS are installed in your system. Once you install the latest versions, the above-mentioned code should work just fine as it is correct syntactically.
If the problem still persists, you can restart your computer and try running the code again.
And if again you encounter the same error, create local node_modules with truffle installed on them. Then execute those copies.