nodejs搭建简易服务器

362 阅读1分钟
原生nodejs:

const http = require('http')
const server = http.createServer((req, res) => {
  if (req.url == '/') {
    res.end('hellow world')
  } else {
    res.end('req.url:'+ req.url)
  }
})
server.listen(3000, function () {
  console.log('running...')
})
express框架:

const express = require('express')
const app = express()

app.get('/',function(request,response){
  response.send('hello world')
})
app.listen(3000,function(){
  console.log('server is running in 3000')
})