How to use app-root-path - 10 common examples

To help you get started, we’ve selected a few app-root-path 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 coountdown / coountdown / main / index.js View on Github external
app.on('ready', async () => {
  // Checking internet connection
  onlineStatusWindow = new BrowserWindow({
    width: 0,
    height: 0,
    show: false,
  })

  onlineStatusWindow.loadURL(`file://${resolveRootPath('./main/static/pages/online-status.html')}`)

  // Update internet connection
  ipcMain.on('online-status-changed', (event, status) => {
    console.log(`connection: ${status.toUpperCase()}`)
    process.env.CONNECTION = status
  })

  electronUtil.enforceMacOSAppLocation()
  updater(app)
  mixpanel.track(app, 'Launch App')

  try {
    tray = new Tray(resolveRootPath('./main/static/tray/iconTemplate.png'))
    tray.setToolTip(config.APP_NAME)
  } catch (err) {
    Sentry.captureException(err)
github linnovate / mean / server / config / express.js View on Github external
// enable CORS - Cross Origin Resource Sharing
app.use(cors());

// enable detailed API logging in dev env
if (config.env === 'development') {
  expressWinston.requestWhitelist.push('body');
  expressWinston.responseWhitelist.push('body');
  // app.use(expressWinston.logger({
  //   winstonInstance,
  //   meta: true, // optional: log meta data about request (defaults to true)
  //   msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
  //   colorStatus: true // Color the status code (default green, 3XX cyan, 4XX yellow, 5XX red).
  // }));
}
app.use(express.static(path.join(appRoot.path, 'dist')));

app.use('/api', routes);

innograph.init('/api/graphql', app, {post: postCtrl});

app.get('*', (req, res) => {
  res.sendFile(path.join(appRoot.path, 'dist/index.html'));
});

// if error is not an instanceOf APIError, convert it.
app.use((err, req, res, next) => {
  if (err instanceof expressValidation.ValidationError) {
    // validation error contains errors which is an array of error each containing message[]
    const unifiedErrorMessage = err.errors.map(error => error.messages.join('. ')).join(' and ');
    const error = new APIError(unifiedErrorMessage, err.status, true);
    return next(error);
github emyann / matron / packages / matron / src / create.ts View on Github external
const templateCacheDir = path.join(appRoot.path, 'cache/templates/src');
  if (isDev) {
    templatePath = path.join(
      appRoot.path,
      'node_modules/@matron/schematics/node_modules/@matron',
      getTemplateLocation(templateName)
    );
  } else {
    templatePath = path.join(appRoot.path, 'cache', getTemplateLocation(templateName));
    if (!p) {
      // ATM lookup matron own templates hosted in github
      // TODO: At some point, should come from npm@version package
      console.log(chalk`{hex('#00b6ff') downloading template ${templateName} from github}`);
      await githubClient().downloadTemplate(templateName, templateCacheDir);
    } else {
      const tempCacheDir = path.join(appRoot.path, 'temp_cache/templates/src');
      ensureDirectory(tempCacheDir);
      // TODO: p param should be computed from template id
      switch (p) {
        case 'now':
          {
            const nowCommmand = [p, 'init', templateName];
            logInstallTemplate(templateName, 'Now CLI');
            executeTask({ command: `npx`, args: nowCommmand }, { cwd: tempCacheDir });
          }
          break;
        case 'cra':
          {
            const craCommand = ['create-react-app', templateName, '--typescript'];
            logInstallTemplate(templateName, 'create-react-app');

            executeTask({ command: `npx`, args: craCommand }, { cwd: tempCacheDir });
github lbryio / lighthouse.js / server / utils / chainquery / index.js View on Github external
host: 'http://localhost:9200',

  log: {
    level : esLogLevel,
    type  : 'stream',
    stream: loggerStream,
  },
});

const queue = new ElasticQueue({elastic: eclient});
queue.on('drain', function () {
  console.log('elasticsearch queue is drained');
});

// Check that our syncState file exist.
fileExists(path.join(appRoot.path, 'syncState.json'), (err, exists) => {
  if (err) {
    throw err;
  }
  if (!exists) {
    fs.writeFileSync(path.join(appRoot.path, 'syncState.json'), '{}');
  }
});

let status = {info: 'startup successful'};

export async function claimSync () {
  try {
    let syncState = await getJSON(path.join(appRoot.path, 'syncState.json')); // get our persisted state
    if (!syncState.LastSyncTime) {
      syncState.LastSyncTime = '0001-01-01 00:00:00';
    }
github MozillaSecurity / virgo / configs / parcel / bundler.js View on Github external
/** @format */

// https://github.com/parcel-bundler/parcel/issues/1005#issuecomment-419688410

const Bundler = require('parcel-bundler')
const Server = require('express')()
const appRoot = require('app-root-path')

const options = {
  outDir: appRoot.resolve('build/app/renderer/development'), // The out directory to put the build files in, defaults to dist
  outFile: 'index.html', // The name of the outputFile
  //  publicUrl: './', // The url to server on, defaults to dist
  watch: true, // whether to watch the files and rebuild them on change, defaults to process.env.NODE_ENV !== 'production'
  cache: true, // Enabled or disables caching, defaults to true
  cacheDir: appRoot.resolve('.cache'), // The directory cache gets put in, defaults to .cache
  contentHash: false, // Disable content hash from being included on the filename
  minify: false, // Minify files, enabled if process.env.NODE_ENV === 'production'
  scopeHoist: false, // turn on experimental scope hoisting/tree shaking flag, for smaller production bundles
  target: 'electron', // browser/node/electron, defaults to browser
  https: false, // Serve files over https or http, defaults to false
  logLevel: 3, // 3 = log everything, 2 = log warnings & errors, 1 = log errors
  hmrPort: 0, // The port the HMR socket runs on, defaults to a random free port (0 in node.js resolves to a random free port)
  sourceMaps: true, // Enable or disable sourcemaps, defaults to enabled (not supported in minified builds yet)
  hmrHostname: '', // A hostname for hot module reload, default to ''
  detailedReport: false // Prints a detailed report of the bundles, assets, filesizes and times, defaults to false, reports are only printed if watch is disabled
}

const runBundle = async (entrypoint, port) => {
  // Initializes a bundler using the entrypoint location and options provided.
  const bundler = new Bundler(entrypoint, options)
github giltig / rxfrf / tools / webpack / configFactory.js View on Github external
const path = require('path')
const webpack = require('webpack')
const AssetsPlugin = require('assets-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const dotenv = require('dotenv')
const appRoot = require('app-root-path')
const WebpackMd5Hash = require('webpack-md5-hash')
const { removeEmpty, ifElse, merge } = require('../utils')

const appRootPath = appRoot.toString()

// @see https://github.com/motdotla/dotenv
dotenv.config(process.env.NOW
  // This is to support deployment to the "now" host.  See the README for more info.
  ? { path: '../../.envnow', silent: true }
  // Standard .env loading.
  : { silent: true }
)

function webpackConfigFactory ({ target, mode }, { json }) {
  if (!target || !~['client', 'server'].findIndex(valid => target === valid)) {
    throw new Error(
      'You must provide a "target" (client|server) to the webpackConfigFactory.'
    )
  }
github OpenZWave / Zwave2Mqtt / lib / Gateway.js View on Github external
/* eslint-disable no-eval */
/* eslint-disable one-var */
'use strict'

const reqlib = require('app-root-path').require
const EventEmitter = require('events')
const comandClass = reqlib('/lib/Constants.js').comandClass
const debug = reqlib('/lib/debug')('Gateway')
const inherits = require('util').inherits
const hassCfg = reqlib('/hass/configurations.js')
const hassDevices = reqlib('/hass/devices.js')
const version = reqlib('package.json').version

debug.color = 2

try {
  const storeDir = reqlib('config/app.js').storeDir
  const customDevices = reqlib(storeDir + '/customDevices')
  let i = 0
  for (const d in customDevices) {
    hassDevices[d] = customDevices[d]
    i++
  }

  debug('Loaded', i, 'custom hass devices configurations')
} catch (error) {
  if (error.message.indexOf('Cannot find module') >= 0) {
github OpenZWave / Zwave2Mqtt / lib / ZwaveClient.js View on Github external
/* eslint-disable camelcase */
'use strict'

// eslint-disable-next-line one-var
var reqlib = require('app-root-path').require,
  OpenZWave = require('openzwave-shared'),
  utils = reqlib('/lib/utils.js'),
  EventEmitter = require('events'),
  fs = require('fs'),
  jsonStore = reqlib('/lib/jsonStore.js'),
  store = reqlib('config/store.js'),
  storeDir = utils.joinPath(true, reqlib('config/app.js').storeDir),
  debug = reqlib('/lib/debug')('Zwave'),
  Tail = require('tail').Tail,
  inherits = require('util').inherits

debug.color = 4

// eslint-disable-next-line no-unused-vars
const nop = () => { }
const ZWAVE_LOG_FILE = utils.joinPath(storeDir, 'OZW_Log.txt')
const readFile = (path) => new Promise((resolve, reject) => fs.readFile(path, 'utf8', (err, data) => err ? reject(err) : resolve(data)))

// https://github.com/OpenZWave/open-zwave/wiki/Adding-Devices#configuration-variable-types
const VAR_TYPES = {
  'bool': (v) => Boolean(v),
  'byte': (v) => parseInt(v),
  'int': (v) => parseInt(v),
  'short': (v) => parseInt(v),
github OpenZWave / Zwave2Mqtt / app.js View on Github external
var express = require('express'),
  reqlib = require('app-root-path').require,
  logger = require('morgan'),
  cookieParser = require('cookie-parser'),
  bodyParser = require('body-parser'),
  app = express(),
  fs = require('fs'),
  SerialPort = require('serialport'),
  jsonStore = reqlib('/lib/jsonStore.js'),
  cors = require('cors'),
  ZWaveClient = reqlib('/lib/ZwaveClient'),
  MqttClient = reqlib('/lib/MqttClient'),
  Gateway = reqlib('/lib/Gateway'),
  store = reqlib('config/store.js'),
  config = reqlib('config/app.js'),
  debug = reqlib('/lib/debug')('App'),
  history = require('connect-history-api-fallback'),
  utils = reqlib('/lib/utils.js');

var gw; //the gateway instance
let io;

debug("Application path:" + utils.getPath(true));

// view engine setup
app.set('views', utils.joinPath(false, 'views'));
app.set('view engine', 'ejs');
github OpenZWave / Zwave2Mqtt / lib / Gateway.js View on Github external
/* eslint-disable no-eval */
/* eslint-disable one-var */
'use strict'

const reqlib = require('app-root-path').require
const EventEmitter = require('events')
const comandClass = reqlib('/lib/Constants.js').comandClass
const debug = reqlib('/lib/debug')('Gateway')
const inherits = require('util').inherits
const hassCfg = reqlib('/hass/configurations.js')
const hassDevices = reqlib('/hass/devices.js')
const version = reqlib('package.json').version

debug.color = 2

try {
  const storeDir = reqlib('config/app.js').storeDir
  const customDevices = reqlib(storeDir + '/customDevices')
  let i = 0
  for (const d in customDevices) {
    hassDevices[d] = customDevices[d]
    i++
  }

  debug('Loaded', i, 'custom hass devices configurations')
} catch (error) {
  if (error.message.indexOf('Cannot find module') >= 0) {
    debug('No custom hass devices file found')

app-root-path

Determine an app's root path from anywhere inside the app

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis