Node.Js Start Coding Example | Part 1

In this article, we will get to know How to start development using Node.js javascript runtime

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!');

The 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!'

Node.Js Start Coding Example | Part 1

Yeah! we run our first NodeJs code!

 

 

 

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments