Node.Js development starts by installing the NodeJS in our system by running the executable file which you can download from here.
The current version of NodeJs is v12.16.1 for this demonstration. We are also using Visual Studio Code as an IDE to do Node.js development which comes integrated with the Terminal window and support for many awesome plugins.
After the successful installation of Node.js and VS Code, we are ready to dive into the Node.js development tutorial from scratch.
Let’s get started!
Node.js provides many in-build modules we can use for development. You can check them out here.
For example, there is a File System that provides any methods to directly do CRUD operations on files.
Just create a new file hello.js in any folder, here we have “~NodeTutorial/hello.js“.
Now add below code in the hello.js file:
// hello.js const fs = require('fs') fs.writeFileSync('new-file.txt','First NodeJs Code!');
writeFileSync method takes two arguments first is the file name which will be created and second is the content to write in the file.
Open VS Code Terminal and move the root to the above folder and run following command:
$ node hello.js
This command will create a new file new-file.txt with content 'First NodeJs Code!'
Yeah! we run our first NodeJs code!