---
title: "Launch Browser from Node Server"
description: "Automatically open the browser when starting a Node.js web server. Practical notes and code examples on Launch Browser from."
url: "https://h3manth.com/scribe/launch-browser-from-node-server/"
canonical_url: "https://h3manth.com/scribe/launch-browser-from-node-server/"
markdown_url: "https://h3manth.com/scribe/blog/launch-browser-from-node-server.md"
publishDate: "2014-01-30T00:00:00.000Z"
author: "Hemanth HM"
category: "node"
tags: ["node","javascript"]
word_count: 106
reading_time_minutes: 1
x_markdown_tokens: 297
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Launch Browser from Node Server

> Automatically open the browser when starting a Node.js web server. Practical notes and code examples on Launch Browser from.

Why launch browser from a Node server?
- Because we are lazy!
- For quick demos
- Quick testing
- Less manual work

## The Code

```javascript
var http = require('http'),
    open = require('open'),
    server;

server = http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
});

server.listen(1337, '127.0.0.1', function() {
  console.log('Launching the browser!');
  open('http://127.0.0.1:1337');
});
```

The only dependency is [open](https://github.com/pwnall/node-open) which opens a file or URI with the user's preferred application (browser, editor, etc), cross platform.

npm install open

In `server.listen(port, [host], [backlog], [callback])`, the callback is added as a listener for the `listening` event - perfect for knowing when to launch the browser!
