<commit_before>var fs = require('fs')
var getport = require('getport')
var debug = require('debug')('get-port')

module.exports = getPort

module.exports.readPort = readPort

function getPort(startingPort, portFile, cb) {
  readPort(portFile, function(err, port) {
    if (err) return newPort()
    gotPort(err, port)
  })
  
  function newPort() {
    getport(startingPort, function(err, port) {
      if (err) return gotPort(err)
      debug('writing new portFile ' + portFile)
      fs.writeFile(portFile, port.toString(), function(err) {
        gotPort(err, port)
      })
    })
  }
  
  function gotPort(err, port) {
    if (err) {
      debug('getport err: ' + err)
      return cb(err)
    }<commit_msg>Adds DAT_PORT environmental variable to set dat serve port<commit_after>var fs = require('fs')
var getport = require('getport')
var debug = require('debug')('get-port')

module.exports = getPort

module.exports.readPort = readPort

function getPort(startingPort, portFile, cb) {
  if (process.env.DAT_PORT) { return cb(null, process.env.DAT_PORT)}
  readPort(portFile, function(err, port) {
    if (err) return newPort()
    gotPort(err, port)
  })

  function newPort() {
    getport(startingPort, function(err, port) {
      if (err) return gotPort(err)
      debug('writing new portFile ' + portFile)
      fs.writeFile(portFile, port.toString(), function(err) {
        gotPort(err, port)
      })
    })
  }

  function gotPort(err, port) {
    if (err) {
      debug('getport err: ' + err)
      return cb(err)
    }
{'fraction_non_alphanumeric': 0.13754889178617993, 'fraction_numerical': 0.0, 'mean_word_length': 3.3732193732193734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2525642', 'n_tokens_mistral': 515, 'n_tokens_neox': 506, 'n_words': 121}