Setting up a Node.js environment involves installing Node.js and npm (Node Package Manager) on your computer. Here are the steps to set up Node.js on your system:
On the homepage, you'll see two versions: LTS (Long Term Support) and Current. For most users, it's recommended to download the LTS version, as it's stable and widely used.
Click on the "LTS" button to download the LTS version of Node.js.
3. Install Node.js:
Run the downloaded installer and follow the installation prompts.
The installer will also include npm, so you don't need to install it separately.
Step 2: Verify the Installation
After installing Node.js, you can verify the installation by opening a command prompt or terminal window and running the following commands:
node -v
npm -v
node -v: This command will print the installed version of Node.js. If you see a version number, it means Node.js has been installed successfully.
npm -v: This command will print the installed version of npm.
Step 3: Optional - Updating npm
It's a good practice to keep npm up-to-date. You can do this by running the following command:
npm install -g npm@latest
Step 4: Optional - Using a Version Manager
If you work on multiple projects with different Node.js versions, you might consider using a version manager like nvm (Node Version Manager) for Unix-based systems or nvm-windows for Windows. These tools allow you to easily switch between different versions of Node.js.
Step 5: Set Up a Project
Once Node.js is installed, you can start a new project by creating a directory for it and initializing it with npm. Open a terminal window, navigate to your desired project directory, and run:
npm init -y
This command initializes a new Node.js project with default settings and creates a package.json file, which will store information about your project and its dependencies.
You're now set up with a Node.js environment and ready to start building applications! You can install libraries and modules using npm install and start writing your code.