nodejs ap.js略述

3064 ワード

var express = require('express');
var bodyParser = require('body-parser');//    body
var app = express();//nodejs http    

//        ,    

//      ,        ,           ,
//            

//  json   body
app.use(bodyParser.json());

//  string  body
app.use(bodyParser.urlencoded({
    extended:false
}));

//   get/post     ,   
//         http://localhost/about
app.use("/about",function(req,res){
    console.log("  ");
    res.send("   get/post     ,   ");
});

//      
//Express              ,            URL    。
//       express.static               :
//Express                          
//__dirname       ,       
//app.use(express.static(__dirname + '/public'));//       public  ,  :node_demo/public/
//        /public         public         
// http://localhost/public/test.html
//http://localhost/public/images/kitten.jpg
//http://localhost/public/css/style.css
//http://localhost/public/js/app.js
//http://localhost/public/images/bg.png
app.use('/public', express.static('public'));

//      localhost    ,     
//   get     
//   app.post()    post     
//         http://localhost
app.get('/',function(req,res){
    res.send('this is get request . hello my nodejs!');
});
app.listen(80);