Express to build a simple Web server

Source: Internet
Author: User

Express to build a simple Web server

When it comes to express, we think of Nodejs as a Web application development framework based on the Nodejs platform. Since it is based on the framework of the Nodejs platform, then you have to install Nodejs first.

First to (nodejs.org) This site download, click to download any version, download good later decompression installation.

Create a folder in its file (right-shift+) to open the command-line tool to create a Package.json file for your app with the (NPM init) command. There are the following steps when creating a Package.json file.

(shift+ right-click) to open the Command line tool input (NPM init) as.



Enter your folder name at the Red line, and all of the following press ENTER until the end



Now you have the Package.json file under your folder. Package.json the information on the express we downloaded next

Download Express

folder (shift+ right) Open the command line tool input (NPM install Express-save-dev) as



Download Express under the Node_modules folder.

Code

Create a new JS file

 //reference Expressvar Express = require (" express");//express is defined as Appvar app = Express (),//app get Transfer method, when the Web site for localhost:8888 or localhost:8888/page corresponding Hello!!!!! App.get ("/",function (req,res) {res.send ("hello!!!!! ");}); Set port to 8888, load successful print Web server startup App.listen (8888,function () {console.log ("web server Startup")})  
">// Reference Expressvar Express = require ("Express"),//express defined as Appvar app = Express (),//app get Transfer method, when website is localhost : 8888 or localhost:8888/page corresponding Hello!!!!! App.get ("/", function (req,res) {res.send ("Hello!!!!!");}); Set port to 8888, load successful print Web server startup App.listen (8888,function () {console.log ("Web Server Startup")})


Because I was creating the Package.json file entry point: (Index.js) is inde.js so we can only use index.js, if you do not want to use index.js, you can also set other JS file name

Express to build a simple Web server

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.