Pre-condition
Install express
install_express
npm install express --save
If not use package.json
to manage package, don't need add --save
Run express server
index.js
const express = require('express');
const port = process.env.PORT; //This is for get port from IIS
var app = express();
app.get('/api', (request, response) => {
response.write('express run on IIS');
response.end;
});
app.listen(port);
Then open your index page http://localhost:[port]/api
, then you should see express run on IIS
one web page
Use app.route() to combine get/post
index.js
const express = require('express');
const port = process.env.PORT; //This is for get port from IIS
var app = express();
app.route('/api')
.get((req, res) => {
res.send('express get method')
})
.post((req, res) => {
res.send('express post method')
});
app.listen(port);