How to use the temp.openAsync function in temp

To help you get started, we’ve selected a few temp 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 znetstar / tor-router / src / TorProcess.js View on Github external
let dnsPort = this._ports.dns_port = await getPort();
		let socksPort = this._ports.socks_port =  await getPort();
		let controlPort = this._ports.control_port = await getPort();
		Object.freeze(this._ports);

		let options = {
			DNSPort: `127.0.0.1:${dnsPort}`,
			SocksPort: `127.0.0.1:${socksPort}`,
			ControlPort: `127.0.0.1:${controlPort}`,
			HashedControlPassword: shell.exec(`${this.tor_path} --quiet --hash-password "${this.control_password}"`, { async: false, silent: true }).stdout.trim()
		};

		let config = _.extend(_.cloneDeep(this.tor_config), options);
		let text = Object.keys(config).map((key) => `${key} ${config[key]}`).join(os.EOL);

		let configFile = await temp.openAsync('tor-router');
		let configPath = configFile.path;
		await fs.writeFileAsync(configPath, text);

		let tor = spawn(this.tor_path, ['-f', configPath], {
			stdio: ['ignore', 'pipe', 'pipe'],
			detached: false
		});

		tor.on('close', (async (code) => {
			if (this.definition && !this.definition.Name) {
				await del(this.tor_config.DataDirectory, { force: true });
			}
			
			/**
			 * An event that fires when the process has closed.
			 *