Node.js+express makes web calculator
May 16, 2016 pm 03:19 PMEnvironment:
Host: WIN10
express installation:
1. Install express-generator
Enter the command:
npm install -g express-generator
2. Install express
Enter the command:
npm install -g express
3 .Verify whether the installation is successful
Enter the command: express -V
View help: express --help
Create the project:
express -e calculator cd calculator && npm install
Run the default web page:
Enter the command: npm start or node ./bin/www
The port is configured in /bin/www.
Can perform addition operations.
Source code:
view/index.ejs: Add input box
routes/index.js: Calculate and push the submitted data Result
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;
[Related tutorial recommendations]
1. JavaScript video tutorial
2. JavaScript online manual
3. bootstrap tutorial

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Teach you how to open the win10 calculator

An article about memory control in Node

Detailed graphic explanation of the memory and GC of the Node V8 engine

How to use express to handle file upload in node project

Let's talk in depth about the File module in Node

What should I do if node cannot use npm command?

Let's talk about the event loop in Node
