ephemeris
ephemeris

Reputation: 785

When running script for express web server with node on windows get prompt to select app

I'm going through this this course currently.

There is a tutorial on how to configure and run express server. The following script is suggested:

var express = require('express');
var path = require('path');
var open = require('open');

var port = 3000;
var app = express();

app.get('/',function(req, res){
    res.sendFile(path.join(__dirname,'../src/index.html'));
});

app.listen(port,function(err){
    if(err){
        console.log(err);
    }
    else{
        open('localhost:'+port);
    }
});

When I run it in project root with $ node buildScripts/srcServer.js I get a system prompt You'll need a new app to open this localhost with the only suggestion being look at windows store.

What's that about? What does it need an app for? In the course when the script is run the browser is opened, but it's on Mac there. When I navigate manually to localhost:3000 there is the error like there is supposed to be, but I'm somewhat concerned that this behavior will mess with live reloading so I'd like to get rid of it.

Upvotes: 0

Views: 22

Answers (1)

S. Dev
S. Dev

Reputation: 619

Add the http:// prefix and it will open using the default browser.

open('http://localhost:'+port);

Upvotes: 1

Related Questions