マイブーム@技術と生活

仕事や生活に関わる技術的なことを記述します。

今どきの開発環境

node-v10.16.3-x64.exe

python-3.7.4-amd64.exe

sakura_install2-2-0-1.exe

df141.lzh

//
// app.js (UTF-8)
//

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

const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const cookieSession = require('cookie-session');

app.use(cookieParser());
app.use(cookieSession({secret: 'app_1'}));

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer(app);


app.post('/', function(req, res) {
  console.log(req.body);
  res.send(200);
});


app.post('/calculation', function(req, res) {
  console.log(req.body.field);
  res.send(200);
});


server.listen(port, hostname, function() {
  console.log(`Server running at http://${hostname}:${port}/`);
});

 

<!-- start.htm -->

<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>


<a href="http://127.0.0.1:3000/">Start</a><br /><br />


<form method="post" action="http://127.0.0.1:3000/">
<input type="text" name="field1">
<input type="text" name="field2">
<input type="submit">
</form>


<form method="post" action="http://127.0.0.1:3000/calculation">
<input type="text" name="field">
<input type="submit">
</form>


</body>
</html> 

Node.js command prompt

node app.js

ブラウザで start.htm を開く