NodeJS Hello World
What is NodeJS?
NodeJS is a cross-platform runtime environment that allows you to run Javascript code, outside of the browser. Originally, Javascript ran within the browser, but as time went on, it's ability and uses were extended, making it one of the most popular tools for back end development development on a server.
What is back end development?
Before we talk about that, let's talk about front end development. Front end refers to what the user can see and interact with, which is all the pretty stuff. Example: the site layout, and the positioning of each element.
But when it comes to the processing aspect, the back end is were all the heavy lifting takes place. Example: processing a payment page, or registering a user onto a site.
How do I install Node?
Step 1: Install Node (https://nodejs.org/en/download/)
Step 2: Create a folder anywhere (Eg: C:\node_projects\hello)
Step 3: Run your favourite command line utility, and change your directory to the folder that you just created.
cd C:\node_projects\hello
Step 4: Initialize npm (Node Package Manager)
npm init -y
This creates a file called "package.json" within your project's root folder, providing information, such as your project name, it's version, and dependencies to the front end. the additional parameter "-y" allows you to skip steps that would require other input.
{ "name": "hello_world", "version": "1.0.0", "description": "", "main": "hello.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" }
Ok, now we are all set.
Open up your favourite code editor, which in our case will be Visual Studio Code (https://code.visualstudio.com/), and within Visual Studio Code, open the folder that you created (C:\node_projects\hello)
Create a new file which we will call hello_world.js
Note: the .js extention is important, as it will imply that we are working on a Javascript file.
Type,
console.log("Hello World!")
Head back to your command line utility and run node hello_world.js
Comments
Post a Comment