Today we will have a look at how to setup your NodeJS project, have fun 🤩 .
Check your nodeJS version
First of all if you don’t have node installed on your machine, then go here and install it.
To see if you have node already installed write this command in your terminal:
node -v
If it displays a similar text to the picture below, then you already have node installed. Otherwise install it asap.
The text tells you what kind of node version you have, in this case my node version is 12.18.3.
Generate your project
Once you have node installed and ready, you can create a new node project, to do that, all you have to do is call npm init in your command line. This command will ask you about the name of your package, project, git repository, author name and other basic info.
npm init
At the end it will display all the info and ask you if everything is OK. Just hit enter and viola you have your first node project set up. If you look in your project folder you should see a package.json with all of the info you’ve just set.
Create and run your first node file
Now all you need to do is create an index.js in your project folder. To create a new file call vim
vim index.js
and add console.log function to display “Hello 👋 “ on the screen.
console.log("Hello 👋")
Now to run your code write
node index.js
Congratulations! 🥳 🎉 🥂
You’ve successfully setup and ran a nodeJS project.
Grab some beer and celebrate, you’ve done a lot work already. 💪🤘🍻
In next post we will look at how to setup babel for our nodeJS project.