Nodejs getting started, nodejs web development getting started, NPM, express, socket configuration and installation, nodejs chat room Development

Source: Internet
Author: User

I. node. JS: The javascript runtime environment on the server side. It features no blocking and event-driven features. It uses the V8 engine to implement web services similar to Apache and nginx, you can use it to build a javascript-based web app. Therefore, you need to know the following when developing with nodejs:
1. How to run the nodejs server language (Interpreter) (similar to Python, you must install the corresponding software in both Linux and Windows to run Python ), generally, the operating environment for installing this language includes Linux and Windows. I will extract it from the official website and give you a brief introduction.
Linux:

(1) Go to the official website to download any version of nodejs for linuxinstallation package (node-v0.6.2.tar.gz );
(2) decompress the compressed package tar-zxvf node-v0.6.2.tar.gz
(3) enter the decompressed folder CD node-v0.6.2
(4)./configure configuration preparation and Installation
(5) make
(6) make install
(7) after the installation is complete, enter the installation folder, which contains a test folder and uses node index. JS to test whether the installation is successful. The method for running a nodejs file is "Node xx. JS"
Windows:

(1) Go to the official website to download an for Windows EXE execution file: http://nodejs.org/dist/

(2) then you can perform a simple test and create a hello. js editing Code as follows:
VaR HTTP = require ('http'); http. createserver (function (req, Res ){
Res. writehead (200, {'content-type': 'text/plain '});
Res. End ('Hello world \ n') ;}). Listen (1337, "127.0.0.1 ");
Console. Log ('server running at http: // 127.0.0.1: 1337 /');
(3) Place the just-downloaded node.exe and hello. js files in the same folder and enter the folder in the Windows cmd running environment;
(4) use node hello. js. (If you have any idea, refer to this document for additional test code or beginners)
(5) The following execution result is displayed:
(6) add node.exe to the system path so that it can be executed anywhere. How to add it to Google.
2. How to develop a web application? In fact, after learning a language, we may ask ourselves or our teachers what are the main uses of these languages, which applications can be developed using these languages. For nodejs, we use an express framework as its web development framework. I will not detail the advantages and disadvantages of this development framework and how to configure it. For details, refer: there are many things in the http://www.csser.com/tools/express-js/express-guide-reference-zh-CN.html, it is recommended that you still develop and use it to learn it, or blindly go to see the document, I do not know how to read it.
If you can refer to the http://www.lzlu.com/blog/ installation? P = 792 this person wrote a good blog! When NPM is installed, you can copy the code, because // is used as a comment,

Actually: curl http://npm.js.org/install.sh | SH (curl http://npm.js.org/install.sh | sudo SH)
To test the express application, follow these steps:
(1) enter any working directory, use: Express testapp (any project name you need to create) to create an application;
(2) Go to testapp and you will see the following files and folders:

(3) Here I do not have a detailed description of each folder to store files, you can view the http://hi.baidu.com/yecell/blog/item/90106ddeaf59284a95ee3752.html this person's post, which can be very detailed description of each folder to store files.

(4) run this project using node app. js to view the following running results:

If the following problems occur:
Error: cannot find module 'express '. Put the corresponding node_modules folder under test_express. node_modules has two app libraries: Express and jade.
(5) Now, you can do some corresponding web development. After reading that Baidu post, you will generally understand it. If you still don't understand it, you can give it a solution at any time.
Ii. Socket installation and configuration

This part is very simple, mainly a installation, how to install it or introduce others to the post http://wayneye.com/ViewBlog.aspx? Blogid = 123 this eldest brother wrote well. There is also a good example in it. Let's learn from it.

3. A group chat web application developed based on express and Socket

You can download this part directly, decompress it directly in the project, and run node chat. JS, access the corresponding URL (127.0.0.1: 3000), and then open two local browsers. I opened them using chrome and Firefox. The specific running result is as follows:

Now, we have introduced all the node. js development configurations. I hope you will enjoy it!

Attachment nodejs chat room

Remember my mailbox Oh: danhuang.hook@foxmail.com problems instant communication, ensure that you reply instantly. Anyone in the technical exchange group can pull me 492383469

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.