How to use the portfinder.basePort function in portfinder

To help you get started, we’ve selected a few portfinder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SirM2z / vue2-all-test / build / dev-server.js View on Github external
// serve pure static assets
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))

const uri = config.dev.openBrowserUriHost === 'http://localhost:'? config.dev.openBrowserUriHost + port : config.dev.openBrowserUriHost

var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
  _resolve = resolve
  _reject = reject
})

var server
var portfinder = require('portfinder')
portfinder.basePort = port

console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
  portfinder.getPort((err, port) => {
    if (err) {
      _reject(err)
    }
    process.env.PORT = port
    var uri = config.dev.openBrowserUriHost === 'http://localhost:'? config.dev.openBrowserUriHost + port : config.dev.openBrowserUriHost
      console.log('> Listening at ' + uri + '\n')
      // when env is testing, don't need open it
      if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
        opn(uri)
      }
      server = app.listen(port)
      _resolve()
github yyssc / ssc-grid / docs / dev-run.js View on Github external
/* eslint-disable no-console, no-process-exit */

import 'colors';
import portfinder from 'portfinder';
import { exec } from 'child-process-promise';
// import ip from 'ip';

portfinder.basePort = 4000;

const SIGINT = 'SIGINT';
let processMap = {};

function output(prefix, message) {
  let formattedMessage = message.toString().trim().split('\n')
    .reduce((acc, line) => `${acc}${ acc !== '' ? '\n' : '' }${prefix} ${line}`, '');

  console.log(formattedMessage);
}

function listen({stdout, stderr}, name) {
  stdout.on('data', data => output(`[${name}] `.grey, data));
  stderr.on('data', data => output(`[${name}] `.grey, data));
}
github jake / screenhole-web / build / dev-server.js View on Github external
// serve pure static assets
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))

const uri = 'http://localhost:' + port

var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
  _resolve = resolve
  _reject = reject
})

var server
var portfinder = require('portfinder')
portfinder.basePort = port

console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
  portfinder.getPort((err, port) => {
    if (err) {
      _reject(err)
    }
    process.env.PORT = port
    var uri = 'http://localhost:' + port
    console.log('> Listening at ' + uri + '\n')
    // when env is testing, don't need open it
    if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
      opn(uri)
    }
    server = app.listen(port)
    _resolve()
github wxsms / blog / build / dev-server.js View on Github external
// serve static posts
app.use('/posts', express.static(__dirname + '/../dist/posts/'))
app.use('/feed.xml', express.static(__dirname + '/../dist/feed.xml'))

const uri = 'http://localhost:' + port

var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
  _resolve = resolve
  _reject = reject
})

var server
var portfinder = require('portfinder')
portfinder.basePort = port

console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
  portfinder.getPort((err, port) => {
    if (err) {
      _reject(err)
    }
    process.env.PORT = port
    var uri = 'http://localhost:' + port
    console.log('> Listening at ' + uri + '\n')
    // when env is testing, don't need open it
    if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
      opn(uri)
    }
    server = app.listen(port)
    _resolve()
github YaoZeyuan / vue-multi-page / build / dev-server.js View on Github external
// 直接打开最新添加的项目,方便调试
let projectList = config.projectConfig.project
let lastedProjectIndex = Object.keys(projectList).length - 1
let lastedProjectUri = uri + '/' + config.projectConfig.staticRoot + '/html/' + Object.keys(projectList)[lastedProjectIndex] + '/index.html'
console.log(`lasted_project_uri => ${lastedProjectUri}`)

var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
  _resolve = resolve
  _reject = reject
})

var server
var portfinder = require('portfinder')
portfinder.basePort = port

console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
  portfinder.getPort((err, port) => {
    if (err) {
      _reject(err)
    }
    process.env.PORT = port
    console.log('> Listening at ' + uri + '\n')
    // when env is testing, don't need open it
    if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
      opn(lastedProjectUri)
    }
    server = app.listen(port)
    _resolve()
  })
github JieRucker / jBlog / client / build / webpack.dev.conf.js View on Github external
module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = process.env.PORT || config.dev.port
  portfinder.getPort((err, port) => {
    if (err) {
      reject(err)
    } else {
      // publish the new Port, necessary for e2e tests
      process.env.PORT = port;
      // add port to devServer config
      devWebpackConfig.devServer.port = port;

      // Add FriendlyErrorsPlugin
      devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
        compilationSuccessInfo: {
          messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
        },
        onErrors: config.dev.notifyOnErrors
          ? utils.createNotifierCallback()
github slipkinem / vue-admin / build / webpack.dev.conf.js View on Github external
module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = process.env.PORT || config.dev.port
  portfinder.getPort((err, port) => {
    if (err) {
      reject(err)
    } else {
      // publish the new Port, necessary for e2e tests
      process.env.PORT = port
      // add port to devServer config
      devWebpackConfig.devServer.port = port

      // Add FriendlyErrorsPlugin
      devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
        compilationSuccessInfo: {
          messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
        },
        onErrors: config.dev.notifyOnErrors
        ? utils.createNotifierCallback()
github njleonzhang / element-ui-pro / build / webpack.dev.conf.js View on Github external
module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = process.env.PORT || config.dev.port
  portfinder.getPort((err, port) => {
    if (err) {
      reject(err)
    } else {
      // publish the new Port, necessary for e2e tests
      process.env.PORT = port
      // add port to devServer config
      devWebpackConfig.devServer.port = port

      // Add FriendlyErrorsPlugin
      devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
        compilationSuccessInfo: {
          messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
        },
        onErrors: config.dev.notifyOnErrors
        ? utils.createNotifierCallback()
github kavanagh / srvlr / index.js View on Github external
console.error(err);
});

function listen(p) {
  server.listen(p);
  log('Listening on port %s', p);
  var url = 'http://' + program.address + ':' + p.toString() + '/' + (program.url || '');
  if (program.open) {
    verbose('Opening browser...');
    !program.log && console.log(pkg.name + ' running at %s', url);
    opener(url);
  }
}

if (!program.port) {
  portfinder.basePort = defaults.basePort;
  portfinder.getPort(function (err, port) {
      if (err) throw err;
      listen(port);
  });
} else {
  listen(program.port);
}
github meteorlxy / vue-showdown / scripts / webpack.config.js View on Github external
module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = webpackDevConfig.devServer.port
  portfinder.getPort((err, port) => {
    if (err) {
      reject(err)
    } else {
      webpackDevConfig.devServer.port = port
      webpackDevConfig.plugins.push(new FriendlyErrorsPlugin({
        compilationSuccessInfo: {
          messages: [`Webpack dev server is listening: http://${webpackDevConfig.devServer.host}:${port}`],
        },
      }))
      resolve(webpackDevConfig)
    }
  })
})

portfinder

A simple tool to find an open port on the current machine

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis