Two+ things I do every time I set up a new node project
Andreas Riedmüller

Andreas Riedmüller @receter

About: Web Developer and Co-Founder an Userbrain and Simplease

Location:
Graz
Joined:
Mar 19, 2019

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

Publish Date: Aug 10 '23
21 2

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.

Comments 2 total

  • lukkea
    lukkeaSep 15, 2023

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

Add comment