DEV Community

Andreas Riedmüller
Andreas Riedmüller

Posted on • Edited on

Two+ things I do every time I set up a new node project

1. Early first commit

Committing regularly is a very good habit. And there is one point in time where it is especially helpful, right after you created a new project and BEFORE you type the first character in your project.

For example, right after creating a new Vite project (or bootstrapping with any other template):

git init
git add --all
git commit -m "blank vite react/typescript project"
Enter fullscreen mode Exit fullscreen mode

This way you can easily spot what you have done and what has been created by create vite@latest for example.

2. Create a .nvmrc file

Working with different versions of Node on the same project might cause unnecessary trouble. So the second thing I do after setting up a node project is to create a .nvmrc file in the project root.

node --version > .nvmrc
git add .nvmrc
git commit -m "created .nvmrc file"
Enter fullscreen mode Exit fullscreen mode

This will create a file named .nvmrc with this content:

v18.16.0
Enter fullscreen mode Exit fullscreen mode

Having done that, any developer can just run nvm use in the project folder and nvm will automatically switch to the correct version of node.

💡Pro Tip You can set up a script that will automatically call nvm use whenever you enter a directory that contains an .nvmrc

(3. Install node's types)

If working with TypeScript I also install the types package for node. Sooner or later you will need this.

npm install @types/node -D
Enter fullscreen mode Exit fullscreen mode

(4. Add a jsconfig.json)

If you are going to use an editor that uses LSP (VSCode, Sublime Text, etc.) make sure you have a jsconfig.json (or tsconfig.json) file for your project. Not having this file might bring you into trouble.

Top comments (2)

Collapse
 
lukkea profile image
lukkea • Edited

Hey Andreas, good tips here, thanks.
You've got a typo in (3. Install node's types): should be a slash between @types/node
🙂

Collapse
 
receter profile image
Andreas Riedmüller

Ah yes, thanks for pointing it out 🙏