DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for 6 tips to make your JS/TS repository more new-joiners friendly

6 tips to make your JS/TS repository more new-joiners friendly

Have you ever wondered how to make your repository more readable and lower the entry-level for new joiners in your team? How to decrease the time needed for onboarding new people and limit questions asked by external people who want to use your solutions or contribute to them? Or how to make it easier just for yourself to recreate the developing ecosystem after reimaging/changing your laptop? Recently, I analyzed many repositories (private and open source) and discovered that some of them are much more friendly to new joiners than others. What makes them so special? Several small things you can implement in your project with really low time and effort costs. Below, you can find 6β€” in my opinion β€” the most useful tips to improve your code repository just today.

#1 Readme

Example of readme fileβ€Šβ€”β€Šshort description of the project

Probably that point is obvious to many of you. But at the same time it’s so important I can’t miss that point in my article. Readme is a file in the root of your git project where you should describe the most essential info about it. What kind of information should be placed there? Definitely, the main purpose of the repository β€” why it was created, what is the purpose of it, who is responsible for that project. Personally, I am also a huge fan of adding a section with specific info on how to install, develop, and deploy code in the repo. Yeah, I know that majority of times in the beginning it will be sth like:

git clone <repository-address>
npm install
npm run start
Enter fullscreen mode Exit fullscreen mode

but remember that our projects are not always so simple! When your repository is growing and you start using subrepositories, monorepos, micro-frontends, complex dependencies, dockers, or advanced logic to deploy, the first run of the app may become a nightmare for a new joiner β€” especially if that’s a person with a different technical background than yours. Adding specific info in the readme about that process (especially formed as a chain of commands to call in a terminal) not only lowers an entry-level to contribute to your repository but also decreases the time needed for onboarding a new person or answering questions from other teams in your company. And it should take less than 5 minutes (in the most basic way you can just copy-paste commands you use each time to start a project from terminal to readme file). Completely, worth it β€” don’t you think? If you need some inspiration, check e.g. github-changelog-generator β€” really nice example of a good readme file!

#2 Scripts in package.json

Screenshot of example scripts in package.json

Package.json is the next, super-essential file in almost every JS/typescript-based project. It’s a file where you can define the version, name, and dependencies for the project. Thanks to that you can just call npm install or yarn to install all dependencies required for your project (in the correct versions!). As a frontend developer, you probably use that all the time. But there is also a section which is, unfortunately, less popular β€” and I’m writing here about scripts. It’s nothing more than a key-value list where you can define your own names for some commands. When you are using e.g. Angular, some of them will be generated during the init of the project β€” like start or test. Although, I strongly encourage you to add your custom ones. If you have a special command to start unit tests, add it to scripts. If you are using some tools to check code styling, add it in that section. If you are using docker, add a script to run it locally there as well. To be honest, almost every command you use in the terminal should be placed here. Benefits are at least two: all useful commands are documented, so a new person in the team can easily check what actions are possible and you receive short, easy-to-remember, and type alias to call in the terminal.

#3 Swagger

Example of swagger file from the official page β€” swagger.io. In the left there is a source code, on the right generated api doc

Defining and documenting API can be a challenging task. Fortunately, we have something called a swagger β€” a set of open-source tools built around the OpenAPI Specification that can help you design, build, document, and consume REST APIs. Thanks to them, you can create a webpage with all endpoints defined with their query params, body params, schemas of the expected response, etc. What’s more, you can also test calls directly from that page. You don’t have to dig into source code to understand APIs. And using or changing your service is much easier, don’t you think? Let’s say some words about how to implement them in our project lifecycles. There are two main approaches to defining swagger: as a contract before development or autogenerating that based on created service code. Both of them have their own cons and pros. Defining swagger file as an API contract before touching a code allows us to parallel work between different teams dependent on that service and create typescript types based on that (useful when your backend is written in Node and you want to share types between repositories). But also requires more effortβ€” all endpoints have to be defined manually and some later changes in service may be missed (developers have to remember about changes in two places). On the other hand, you can use annotations to generating swagger files automatically, based on source code β€” using libraries available for almost all languages. Thanks to that you don’t have to worry about updating documentation, but all consumers have to wait for a working version of API to start their work and some comments. Nevertheless, no matter which option is better in your case, using swagger definitely can take your API documentation to a completely new level.

Note: Very often your swagger contract will be defined in a separate repository. If so, remember to add a swagger link to the Readme file in the main project. Be nice to others, don’t make them search for that (or worse, miss knowledge it exists)!

#4 Tests

A board with text Tests are for people who make mistakes. Part who make mistakes is strikethrough, so final text is β€œTests are for people”
Probably, the most surprising point here. But well-written tests may be a much better source of knowledge about the repository than traditional documentation. Docs can lie β€” code never! When I have a problem with understanding some part of a system, I’m always taking a look at a unit or functional tests for that. It simple way to check which use cases were predicted by the code author and how it should work. And good tests increase also the quality of your project. Double win!

#5 .nvmrc

A little thing, but makes me happy! A .nvmrc file allows you to define and document the node version used in the project. It’s only one line, but whoever was struggling with a broken installation and had no clue what’s wrong, will appreciate it. Especially, because errors printed in the terminal are not suggesting the wrong node version at all! Using .nvmrc it’s enough to call nvm use before npm install and the correct node version will be used. So small, so nice!

Black cat sitting in the front of the computer with opened source code

#6 Code styling rules & automation

Please, don’t waste your and others' time on manually checking indents or formatting rules. And write them down instead of saying β€œWe always do it that way” during code review. I know that β€œspaces vs tabs” is a holy war in programming but you have to decide that battle for your team. Add tools like eslint or prettier and a set of rules to your repository. Automate that checks. Test your formatting on pre-commit or creating merge requests. Define rules in a transparent way β€” not only in your head. And let a computer do that simple checks β€” it is the best at that!

Summary

Of course, the list presented above is not exhausted and there are many more ways to improve your codebase to make it more new-joiners friendly. But all tips presented by me are easy to implement and β€” in my personal opinion β€” have a huge impact on people who want to start work with your repository. I hope, you will find that article useful! If so, click the β€œclap” button or leave a comment below. Happy coding!

Top comments (3)

Collapse
balastrong profile image
Leonardo Montini

Thanks for the article, in particular for swagger and nvmrc, which I usually forget on my projects πŸ˜…

Next to README.md I would also add one more file on the root and is CONTRIBUTING.md. You can (and should) indeed put some short instructions on how to run the app on the main readme, but it's also nice to have a separate file with more in-depth instructions on working on the repo itself.
Details such as particular dependencies, coding standards, troubleshooting in setting up the projects... practical stuff that might not fit well in a potentially long readme.
Anyway, I see there's already one in the repo you used as a good example, which is awesome πŸ˜‰

When I want to start contributing on the project is most of the time the second file I look for, right after the readme :)

Collapse
domizajac profile image
Dominika ZajΔ…c (she/her) πŸ‡΅πŸ‡± Author

Totally agree! Good Contributing.md is essential especially in open source projects or when team works remotely.

Collapse
eshimischi profile image
eshimischi

Swagger is suitable for REST projects, i chose GraphQL long ago, there are a lot of same documentation tools for it too

Find what you were looking for? Join hundreds of thousands of developers on DEV so you can:

Β 
🌚 Enable dark mode
πŸ”  Change your default font
πŸ“š Adjust your experience level to see more relevant content