How To Setup Node.Js In Windows And Create Testapp

There are 2 ways for installing node.js. Either using raw source code or using package manager. I will be explaining installation using package manager because that’s the easiest way.

Download package from the following link and install it.

http://www.nodejs.org/

for testing whether it is installed correctly fire up command prompt and type innode and press enter. then enter the following code:

 

console.log(‘Hi Yourself!!’)

if installation was successful then it will display

Hi Yourself!!

undefined

undefined is the return type…

Now we are going to install the Web framework needed for creating app

Node.js has got an in built server and we are using ‘express’ as the framework which is very easy to install…

For installing express, type

npm install -g express@2.5.8

or

npm install -g express

-g is because the package should be globally installed.

it is recommended to specify the version as in the first code.

now we can try creating a testapp

create a folder say, NODE APPS where ever you want to keep your node apps.

navigate into that folder and type in

express testapp

this will create a testapp inside the folder NODE APPS..and display something like:

create : testapp
create : testapp/package.json
create : testapp/app.js
create : testapp/public
create : testapp/public/javascripts
create : testapp/public/images
create : testapp/public/stylesheets
create : testapp/public/stylesheets/style.css
create : testapp/routes
create : testapp/routes/index.js
create : testapp/views
create : testapp/views/layout.jade
create : testapp/views/index.jade

dont forget to install dependencies:
$ cd testapp && npm install

Now we are going to install dependencies. There is a file inside the testapp folder called ‘package’. open it using any text editor and edit so that it looks like:

{
“name”: “testapp”
, “version”: “0.0.1”
, “private”: true
, “dependencies”: {
“express”: “2.5.8”
, “jade”: “0.26.1”
, “mongoose”: “*”
}
}

then take the command prompt again and navigate into the app folder and type

npm install

this will hopefully install all the dependencies as specified in the above file

after completing type

node app

this will hopefully display

Express server listening on port 3000 in development mode

keep the command promt running and take a web browser and type in the following url

http://localhost:3000/

If everything went well then it will display

Express

Welcome to Express

Congrats you have created your testapp!!

Leave a Reply

Your email address will not be published. Required fields are marked *