node - express realize hello world

Create a folder, and then create index.js within the folder

1.package.json

npm init -y

2. Install

npm install express ---save

3.index.js

// entry file
//
// 1. Load express module 
var express = the require ( 'express' );


// Create a app object (similar to creating a server object) 
var app = Express ();

// request listener specified route through the middleware 
app.get ( '/ index', function (REQ, RES) {
    res.end('hello world');
});

// 3. Start Services 
app.listen (9092, function () {
    console.log('http://localhost:9092');
})

start up

node index

 

 

Guess you like

Origin www.cnblogs.com/ellen-mylife/p/11014157.html