Node.js Hello World Application

After connecting your Windows server click "Node.js command prompt" under Node.js folder in Start menu. If you didn't install Node.js, you can install it by reading How to Install Node.js on Windows Server? post and then you can run "Node.js command prompt".

In "Node.js command prompt" screen, you can create your first application with the following commands. So what are the meanings of these commands?

Node.js Hello World

For those who do not know how to use command prompt, I want to explain 2 commands I use on the screen, regardless of the Node.js command prompt.

cd: change directory

mkdir: make directory

"cd C:\" command will change your current directory to main directory of C driver. "mkdir nodejs" command will create a new folder inside current folder.

Once you have created the C:\nodejs\helloworld directory and go to this directory, you can run the npm package builder to create a new Node.js application using the command "npm init". Package builder will ask you some informations respectively name, version, description, entry point, test command, git repository, keywords, author and license. You can create your application with default values (values inside paranthesis) with pressing enter key. I just change description and author fields. Once you have completed the information, you can create your application by checking the preview of your package.json file and pressing the enter key.

"echo console.log("hello world"); > index.js" command will create a file named index.js inside your current directory and writes "console.log("hello world");" into index.js file. The index.js value in this command must be the same as the entry point value. Finally, when you run your application with the "node index" command, you will see "hello world" text which you print it on the screen with "console.log" code line.

Congratulations, you have run your first application after installing Node.js in your Windows server on AWS.

How to Install Node.js on Windows Server?

After connected to your Windows Server on AWS, you can download latest Node.js version from https://nodejs.org with the help of Internet Explorer. If you don't know how to connect your Windows server, you can connect it by reading my Connect to Windows Server on AWS post.

node.js Download

Run setup file and complete setup.

Node.js Setup Steps

Congratulations. You have successfully install Node.js on your server.

Node.js Command Prompt

Next post will be about writing a hello world application runs on Node.js.

Connect to Windows Server on AWS

If you don't create a Windows Server on AWS, you can create it by reading my Create a Free Windows Server on AWS post. If you have created your server, click "Connect" button after selecting server which named "Windows Server 2016" under "Instances" page.

Connect

In "Connect To Your Instance" panel after clicking "Download Remote Desktop File" button to download .rdp file, click "Get Password" button to get "Administrator" password.

Connect To Your Instance

In this step, we need key-pair file which we created in previous blog post. My key-pair file name is "Windows2016Server.pem", that's why it asks us to choose Windows2016Server.pem file. After file selection, click "Decrypt Password" button.

Decrypt Password

You can see password of your "Administrator" user.

Username Password

When you open .rdp file which we just downloaded, click "Connect" button to bypass that warning. Copy password which you see in "Password" section, paste it as password of your "Administrator" user and click "OK" button. You can bypass warning about certificate by clicking "Yes" button.

Enter Your Credentials

When you connect to your server, you can see details of your server in upper right corner of the screen.

Server Details

Congratulations. You have successfully connected to your Windows server. Next blog post will be about how to install node.js to this server.

Create a Free Windows Server on AWS

If you don't have an AWS account, you can create it by reading my Create an AWS Account post. If you create your account, login to your account, go to https://console.aws.amazon.com address and select EC2 under Services.

Services EC2

Click "Launch Instance" button under Create Instance panel.

Launch Instance

In this step choose operating system of your server. In this post we will continue by creating a Windows server. To do this click "Select" button next to "Microsoft Windows Server 2016 Base".

Microsoft Windows Server 2016 Base

Once you have selected t2.micro as our server type, click "Next: Configure Instance Details" button.

Instance Type

You can click "Next" button without making any changes in "Configure Instance", "Add Storage" and "Add Tags" steps.

Note: You can make changes to the settings in these steps, but you should not exceed your needs when making your selections. Otherwise, your credit card may be charged.

We will make some changes in "Configure Security Group" step. To provide RDP, HTTP and HTTPS access to our server, we need to add these rules (RDP attached by default) first. In addition, you can add 8080 and 3000 ports to use for development. If you want to access your server from anywhere, you need to select "Anywhere" as "Source" property. If you want to restrict access, you can enter IP address by CIDR (Classless Inter-Domain Routing) notation after selecting "Custom" or "My IP". After you have done your settings, click "Review and Launch" button.

Configure Security Group

In the last step, click "Launch" button after review your server properties.

Launch Instance

In order to connect to the server, you need to have a key pair file. To create a key pair file click "Create a new key pair", give a name in "Key pair name" field and click "Download Key Pair" button. After download of your file, click the "Launch Instances" button.

Note: You need to save key pair file where you have access and you should not lose your key pair file. You can download this file only the first time you create it. There is no panel you can download later.

Create a new key pair

Your server is in preparation phase. Click the "View Instances" button to see status of your server.

View Instance

It takes a few minutes to be ready. You can see the state of your server in "Instance State" field.

Instance State

You can give a name to your server to easily find it when you have lots of servers. When you hover "Name" field, there will be a pencil icon. Click pencil icon and give a name to your server.

Edit NameName Edit

Congratulations. You successfully created a Windows server. Next blog post will be about how to connect this server remotely.