logo
TOOLS TO HELP YOU LEARN
teachers, students, everyone
Tools | Blog | Account | Learn
Login Status
Have an Idea for a Blog Post? Submissions are welcome, click here.

Getting Started with NodeJS
Installation and running your first app
Dec 30, 2016

INSTALL
Go to: https://nodejs.org/en/
Download and install the package (should be a simple double click and follow onscreen directions).

Once installation is complete you should be able to go to Terminal and type in the following commands

node -v
npm -v

as long as each of the above commands returns a version number NodeJS should be installed correctly.

You can now use the 'npm' command to install further packages.

RUN YOUR FIRST NODEJS APP

Create a folder named node_hello on your desktop. In a html/text editor (I use the free editor brackets) create a file called package.json - save this file in the node_hello folder. Note: this step is not nescessary, but it's a good habit to create package.json files with each project.

   {
"name": "Hello-World",
"version": "0.0.0",
"description": "My First Node App",
"main": "server.js",
"author": "LearnEDU",
"dependencies": {
}
}

Next, in terminal, navigate to the 'node_hello' folder and run the following commands.

npm install express --save

If you check your package.json file now you'll notice 'express' listed in the dependencies array. the "--save" take care of this. Express is a common package used with NodeJS. It allows you to simplify your nodeJS code.

Next, create a file called server.js and save it in the same folder. Add the following code to it.

var app = require('express')();
var http = require('http').Server(app);


app.get('/', function(req, res){
  res.send('<h1>Hello Anyone</h1>');
});



http.listen(3000, function(){
  console.log('listening on *:3000');
});

Next, in terminal run the following command 'node server.js'

You can now go to GO TO http://127.0.0.1:3000/ in browser to view this application. You should see words 'Hello World' on the screen. Congrats, you created your first nodeJS application.

Comments:



mmemmo3855
I like it.
2016-12-30 10:51:50

blog

Past Posts

Dropbox Public Folder Alternative
Jun 4, 2017

Getting Started with NodeJS
May 1, 2017

Scratch Intro: Racing Game
Jan 15, 2017

Five Best Educational Tools For Teachers
Feb 3, 2017

Coding Gravity
Feb 22, 2017

Drones in Eduction
March 2, 2017

Javascript Intro
April 1, 2017

iPhone Streaming Audio App
April 15, 2017

Installing MySQL
May 15, 2017

 

 


 

Thank You!