環境:
主機:WIN10
express安裝:
1.express-generator 3 .驗證是否安裝成功 輸入命令:express -V查看幫助:express --help 執行預設網頁: 輸入指令:npm start或node ./bin/www 連接埠配置在/bin/www。 可以執行加法運算。 npm install -g express-generator
npm install -g express
express -e calculator
cd calculator && npm install
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', {
title: '计算器V1.0 by jdh',
numa: 0,
numb: 0,
sum: 0
});
});
router.post('/', function (req, res) {
console.log("接收:", req.body.num1, req.body.num2);
var sum = parseFloat(req.body.num1) + parseFloat(req.body.num2);
console.log('sum = ',sum);
res.render('index', {
title: '计算器V1.0 by jdh',
// numa: req.body.num1,
// numb: req.body.num2
numa: req.body.num1,
numb: req.body.num2,
sum: sum
});
});
module.exports = router;