我使用angular2和var express = require('express');
var app = express();
var sql = require("mssql");
// config for your database
var config = {
user: 'sa',
password: 'EnakAja123',
server: '192.168.1.37',
database: 'Angular'
};
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', false);
next();
});
app.post('/user', function (req, res) {
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.input('username', req.body.username) <<
request.input('password', req.body.password) <<
request.query('select * from Angular_user where username = @username and password = @password', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
});
var server = app.listen(5000, function () {
console.log('Server is running..');
});
连接到SQL Server。
这是我的代码
$ ls
vehicle car.txt bicycle.txt airplane.html train.docx (more files)
如何为此request.body.username和密码插入值?
因为我不知道这个请求和响应是如何工作的