Play the Nodo.js series: Hello World Web Program

Source: Internet
Author: User
Tags dota

Disclaimer: This article is original article, if need reprint, please indicate source and keep original link allong, thank you!

"Rolling the Yangtze River East died of water, spray Amoy heroes." The right or wrong turns empty. -"Linjiang Xian Yang Shen Ming"

Very familiar with the melody, chicken soup A bit: The college entrance examination is a starting point, learn to find a good school, known as genius, work is a watershed, serious work, studious, Jin body great god. Don't worry too much about what you get in the past, what do you want to stare at the future?

A-One: Creating a Node Environment

  Windows (X64)

Download the installation package, fool-only installation, and bring your own NPM Package Manager (Node Pakeage Manager) to bring you to fly.

V4.6.1 Portal: Official website (current stable version, applicable to novice, need FQ)

V6.9.0 Portal: Official website (including the latest features, the official website is that you are the big God to play, deploy or use the above version of it)

Not to install the page always feel sorry who like:

    

  POSIX series:

Debian/ubuntu:

sudo Install Nodejs

Redhat/centos:

sudo Yum Install Nodejs

On the Linux platform compared to the pit dad, you may not download the latest version, this is why? Why is it? Why is it? Linux version update speed is much slower than Nodejs, a kind of old cow dragged the car feeling, sex sex ~

    

At this point if you are really looking for a version of the upgrade, and familiar with the Linux compilation, you can use the direct make source code to deal with the way.

The source code is also cross-platform, feeling is a seed. avi, what player can see, Portal: official website source code (V4.6.1 need FQ).

    The above system requires the installation of Apt-get/yum:

C + + compiler: g++ OR C + + Tools

Python (2.7.2 above, phython3 version below, general system comes with Python, version number self-examination python--version)

Libssl-dev SSL/TLS encryption support

    

  MAC OS X:

    Portal: Official website (stable version V4.6.1,fq bar juvenile) Direct installation

Ps:homebrew is a different kind of posture.

    

a-two:the First Node page:hello world!

The first output of the vast majority of programmers: Hello world.

Suddenly think of the day in school to play DotA, DotA still in World of Warcraft, there is a big God classmate ID is Hello Word,dota play, code to go, the big God turned into Tx,dota still in, just people different.

Pull away, take a look at the code, write a hello.js file:

1 //invoking the HTTP module provided by node. JS 2var http = require ('http'); 3  4 //Create an HTTP server, listen for access 5 //@param req Request Object 6 //@param Res Response object, the response to be made upon receipt of the request 7var server = Http.createserver (function(req, res) {8     //Output Response Header 9Res.writehead ( $, {'Content-type':'text/html'});Ten     //Write Content OneRes.Write('Hello World'); A     //end, if not write, the request has been in the pedding state, can be annotated to do the test -res.end (); -}). Listen ( the);//listening on Port 3000 the  -Console.log ("HTTP Server is listening at Port");

Window7 dos, switch to the path where the Hello.js is located, execute:

Node Hello.js

  

Whoa, rub, cheat me, I want to call the police! Node how to become Supervisor(hidden debugging skills point), juvenile don't square, hold me, behind tell you!

  Local browser access (same as 127.0.0.1 access):

  

Oh, it seems to have missed a supervisor:

After node executes the script, after you update the script content, no matter how to brush the browser, the results will not change. This is because node. js only parses the script the first time it is referenced and then puts the resident memory to avoid repeating the load wasting resources. But as a coder, I want to be visible every time the modification is saved.

Install -G supervisor

Use Supervisor to start the script and debug it perfectly.

How, through this study, you get started? Not fine, welcome to shoot Bricks ~

deploy to a local vagrant server:

  

Browser access:

  

Oh, easy to use, get it done! This is an API interface environment, you can easily play the front and rear end of the separation.

Play the Nodo.js series: Hello World Web Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.