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