feross / hostile

Simple, programmatic `/etc/hosts` manipulation (in node.js)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Last hostname entry doesn't work on Alpine Linux

tobiasc opened this issue · comments

I'm using hostile to add an IP to the hosts file to make it easy to set up our testing flow. We're using a mix of Mac, Windows, & Alpine Linux servers. This works fine on Mac/Windows, but not on Alpine Linux, which is within Docker, so I'm not entirely sure whether the trouble is caused by Docker or Alpine Linux.

Here's the (simplified) code that I'm using:

var hostile = require('hostile');
hostile.set('127.0.0.1', SERVER_URL, function (err) {
    console.log('Set up /etc/hosts');
});

Here's before/after screenshots of my /etc/hosts file:

Before
screen shot 2016-07-14 at 17 24 16

After
screen shot 2016-07-14 at 17 16 52

It looks like the last line break is inserted before the last entry and not after. I've tried manually updating the file, by adding a line break after the last entry, which will make it work in all environments.

Fixed in 1.0.3