1. Ecological networks often have a modular structure with groups of nodes that interact strongly within the group and weakly with other nodes in the network. A modular structure can reveal underlying dynamic ecological or evolutionary processes, influence dynamics that operate on the network, and affect network stability. Consequently, detecting modular structures is a fundamental analysis in network ecology.2. Although many ecological networks describe flows, such as biomass flows in food webs, disease transmission or temporal interaction networks, most modularity analyses have ignored these dynamics, which can hinder our understanding of the interplay between structure and dynamics. Here we present Infomap, an established community-detection method that maps flows on networks into modules based on random walks. To illustrate and facilitate the usage of Infomap on ecological networks, we also provide a fully documented repository with technical explanations and examples, and an open-source R package, infomapecology.3. Infomap is a flexible tool that works on many network types, including directed and undirected networks, bipartite (e.g., plant-pollinator) and unipartite (e.g., food webs) networks, and multilayer networks (e.g., spatial, temporal or multiplex networks with several interaction types). Infomap can also use additional relevant ecological data, which we illustrate by investigating how taxonomic affiliation as node metadata influences the modular structure. 4. Flow-based modularity analysis is relevant across all of ecology and transcends to other biological and non-biological disciplines. It includes natural ways to analyse directed networks, take advantage of metadata, and analyse multilayer networks. A dynamical approach to detecting modular structure has strong potential to provide new insights into the organisation of ecological networks, that are more relevant to the system/question at hand, compared to methods that ignore dynamics.