LoginSignup
0
2

More than 5 years have passed since last update.

Setup node.js express server on IIS

Last updated at Posted at 2018-09-10

Pre-condition

  1. Setup IIS and your web side
  2. Install Node.js
  3. Install iisnode

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);
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2