後端路由實際上是一個WEB服務器後端
路由: 之前是多頁面服務器
如今流行單頁面ui
const http = require( 'http' )url
const host = 'localhost'server
const port = 4000路由
httpit
.createServer( ( req.resp) =>{console
switch (req.url){require
case '/home'require
res.write( 'home' )
res.end()
break;
case '/shopcart'
res.write( 'shopcart' )
res.end()
break;
}
})
.listen( port,host,()=>{
console.log( `the server is running at:http://${ host }:${ port }`)
})