A brief introduction to Vue node. js

Source: Internet
Author: User
Tags node server

First, what is node. js?

It is a service platform that can run JavaScript, it can be used as a back-end program, but its development language is JavaScript

Second, installation

1. Node. JS Features:

- non-blocking IO model -time-driven

2, the use of the scene:

- high concurrency and low traffic - real-time scenarios -chat, ecommerce, live video, etc.

3. Installation Address:

http://nodejs.cn/
Determine if the installation was successful NODE-V
Enter edit state: node+ Enter, you can perform some operations
Exit edit mode: Ctrl+d or CTRL + C two times

4, NPM is a package manager, is actually a command. Use it to install or uninstall packages

Initialize the project first: NPM init (Fast initialize: NPM init-y), Generate files: Package.json

NPM Install package name--save---save---save: Bar Dependency Package added to the running environment

Three, simple use

Templating Development:

Stu.js

var man= "Haiyan"= man;  // Opening interface Console.log (man);

Stu2.js

var temps = require ("./stu.js");  // reference file, in the JS file add a./Representative is a sibling directory Console.log (temps);

So how do you execute the file? Node B.js ===== "Node filename

Iv. simple login with node. js

Login.html

<! DOCTYPE html>span{color:red; }    </style>functionLogin () {varUsername = $ ("#username"). Val (); varPassword = $ ("#password"). Val (); varurl = "Http://localhost:8080/login";        Console.log (Username,password); $.post (URL, {Username,password},function(response) {Console.log (response); if(response) {$ ("span"). HTML ("Login successful")            }Else{                $("span"). HTML ("Login failed")            }        })    }</script></body>

Server.js

varExpress = Require ("Express");//Reference Packagevarquery = require ("querystring");varApp = Express ();//InitializeApp.listen ("8080",function() {//MonitorConsole.log ("Service has started, port is 8080")});varData2= ""; App.post ('/login ',  function(request,response) {Response.header ("Access-control-allow-origin", "*"); Request.on ("Data",function(datas) {//To receive data from the user, it is not changed, it has to be called dataData2 = ""; //Console.log (datas);//<buffer 6e 6d 3d------                                //> The result of this printing is the buffer type, so we have to stitch it up and use QueryString to convert the module into a string .data2+=datas;      }); Request.on ("End",function() {//start parsing after receiving data from the userConsole.log (Query.parse (data2));//{username: ' Haiyan ', Password: ' 123 '}          varUsername =Query.parse (data2). Username; varPassword =Query.parse (data2). password; if(username = "Haiyan" && password = = "123") {response.send (true)//return data to the front End if login is successful}Else{response.send (false)          }      })  });

Note: When started ===>node server.js

A brief introduction to Vue node. js

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.