Contact Us

Essentials of Node.js

Part-3 Node.js Source Code Files

Brief Introduction
This is going to be a very easy tutorial. It aims to describe how to write node.js source code in files ending with a .js extension. Various IDE's and editors for editing node.js files are also outlined in this tutorial. If you already know what IDE to use and how to save and execute Node.js files, then you can skip this one.
When it comes to the choice of an Integrated Development Environment or IDE, it's really a personal choice and different IDEs may be suitable for different projects. Here're the 3 options for you to begin with.
1. Notepad ++ | Download Notepad ++
Here's a screen-shot of a file being edit using Notepad++

2. Sublime Text ++ | Download Sublime
Here's a screenshot of sublime in action

3. Visual Studio Code | Download Visual Studio Code
Here's a screenshot of Visual Studio Code in action
You don't really need to understand the above code right now. It's just a trailer of simplicity of Node.js We'll write a lot more code in following parts of this workshop and try to understand each and every code snippet in detail.
Write code to a file!
After you've chosen your IDE, it's time to write code. Just open your IDE and copy the following code snippet into it. It's a simple program to count the sum of numbers 0-10. Once done, save your file as SimpleSum.js

		@name:        SimpleSum.js
		@description: A Simple Program in Node.js to print sum of numbers 0-10.
		@author: 	  @rishabhio

var total = 0, count = 1;
while (count <= 10) {
total += count;
count += 1;
Execute the code file
Use the node command from windows command prompt or Linux shell to execute your code file.

you@yourpc ~
$ node SimpleSum.js
55 is the result of execution of the Node.js program we wrote. Now we know how to create a source code file and how to run it. In case you face any problems. Feel free to ask questions in comments.

developed & nourished with by rishabh.io