In an ideal truss, this is actually true. As all members in an ideal truss are pin-connected (meaning the nodes cannot support any moments) the members themselves can only be loaded in compression or tension, not shear. Thus, they do not experience any moment either. There are 4 assumptions made for ideal trusses:
- joints are friction-less
- members are assumed to be weightless
- nodes are only at the ends of members
- all loads attack at nodes
These are some severe simplifications, but this can be accounted for by other means.
The main reason why idealised trusses are/were used is because they facilitate calculations a lot.
If you have done some calculations on beams, you may know how complex things can get, as soon as you get into statically indeterminate structures.
Before computer allowed to solve complex statical problems with methods like FEM, simplified systems like trusses were of great help.
It must be noted that e.g. the nodes of truss bridges are not really constructed with pin supports, as this is not really practical for larger structures. Often the members are actually welded or bolted together in a way that doesn't allow rotations like an ideal truss would. But with large enough safety factors, as well as a stiff enough design (steel comes in quite handy with an elasticity of $200$ $GPa$) the necessary rotation in the truss nodes is minimal.
Concerning points 2 and 4 of the "ideal truss rules", this seems to be counterintuitive at first. But firstly, the normal forces modern I-beams for example can take is a multiple of its own weight. Furthermore, methods have been in use to approximate the weight distribution, such as the following:
(This is just an example)
Here, the mass of the entire truss $m$ is approximated by a uniformly distributed load $$q=\frac{m\cdot g}{L}$$, which is then replaced by point loads $Q$ at the nodes. $$Q=q\frac{L}{5}$$
addendum:
Fixing both supports of the truss creates the same problem as with a regular beam: It becomes statically indeterminatei. Consider a beam, fixed at both ends. When this beam experiences a change in temperature it would want to contract or expand, however the two fixed supports prevent that from happening. Thus, resulting in tensile or compressive stresses.
This is the same for trusses. Note how the truss basically consists of triangles. Imagine one of the members experiencing an increase in temperature, therefore expanding. To allow this, the other two members of said triangles just rotate to allow for that expansion. Consequently no thermal stresses occur.
In statically indeterminate trusses this is however prevented by the fixed supports, or by the shape of the truss itself (see footnote i).
i Note that trusses can be statically indeterminate even when there are not two fixed supports. Basically any truss where you could remove $n$ members without the system collapsing is $n$-fold statically indeterminate.