javascript Express - 简单的路由演示

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Express - 简单的路由演示相关的知识,希望对你有一定的参考价值。

var expess = require('express'); //bring in the express module by using require express
var app = express(); // set the app variable to express

// Route that responds with 'hello world' when a GET request is made to
// Set a route for GET request
// First parameter is the the route we want, slash, which represents the hompage
// Second parameter is a call back function that takes a request and a response object
// Inside the callback function we're taking the response object and calling the send method, which is just going to send text to the screen
app.get('/', function (req, res) {
  res.send('hello world';)
});

// POST method route
// Handles a post request to the same endpoint
// You can use the same route with different request types
app.post('/', function (req, res) {
  res.send('POST request to hompage')
})

以上是关于javascript Express - 简单的路由演示的主要内容,如果未能解决你的问题,请参考以下文章

javascript 简单的Express Server

简单的 Node/Express 应用程序,函数式编程方式(如何在 JavaScript 中处理副作用?)

NodeJS:Express 框架实战解析视频教程

Express之Hello World示例

javascript Express 1 - Découverted'express

使用 Express 时未加载 Javascript (Angular)