In this short tutorial we are gonna see how to count lines of code that you've written.
Before we get started you should have node, npm, npx installed in your machine.
Let's start
- Open terminal and cd to your project directory.
- Run the following command
npx sloc .
or you can install sloc package globaly.
npm install -g sloc
run command with sudo if you using linux or mac.
then you can run
sloc .
If you want to exclude file or directory( Like venv or node modules) you can do like that.
sloc . -e <file>|<directory>
Example :
- Here I have a django project in which i have
venvfolder that i wanna exclude.
Thanks for reading.
Happy coding 😎.

Top comments (1)
You shouldn't need to run anything with
sudofor this kind of purpose.I'd like to point out that "source lines of code" is a very dodgy metric to use for anything. It depends entirely on things like the language you use and the formatting you use and the sloc algorithm your software is using to measure things. Not only that, but the number of lines you've written rarely has anything to do with how much work you've done, how much progress a project has made or how many features have been completed.
It's probably useful if you want a summary of how much has changed since a previous date, but you can get that using a diff in your VCS. For instance,
git diff --name-only old-version-tagis likely to give you something that's of more practical use than knowing your code includes 143 block comments.