How to use the cwd function from process
Find comprehensive JavaScript process.cwd code examples handpicked from public code repositorys.
process.cwd is a method in Node.js that returns the current working directory of the Node.js process as a string.
GitHub: ZhangGe6/onnx-modifier
22 23 24 25 26 27 28 29 30 31
electron.app.quit(); return; } electron.app.on('second-instance', (event, commandLine, workingDirectory) => { const currentDirectory = process.cwd(); process.chdir(workingDirectory); const open = this._parseCommandLine(commandLine); process.chdir(currentDirectory); if (!open) {
GitHub: gx0r/agilegps
87 88 89 90 91 92 93 94 95 96
host: os.hostname(), pid: process.pid, date: new Date(), stack: err.stack, argv: process.argv, cwd: process.cwd(), memory: process.memoryUsage(), uptime: process.uptime(), promise: false, uid: process.getuid && process.getuid(),
How does process.cwd work?
process.cwd
is a method in Node.js that returns the current working directory of the Node.js process as a string.
When process.cwd
is called, it returns the path to the current working directory of the Node.js process.
The current working directory is the directory in which the Node.js process was started, and is the base directory for all relative paths used in the process.
For example, if the Node.js process is started from the directory /home/user/project
, then the current working directory will be /home/user/project
. If the process then tries to open the file ./data/file.txt
, the full path to the file will be /home/user/project/data/file.txt
.
process.cwd
can be useful for determining the current working directory of a Node.js process, which can be important for resolving relative paths, accessing files, and performing other operations that depend on the current working directory.
GitHub: sinedied/backslide
60 61 62 63 64 65 66 67 68 69
`; class BackslideCli { constructor() { this._stderrWrite = process.stderr.write; this._pwd = process.cwd(); } /** * Runs command with specified arguments.
26 27 28 29 30 31 32 33 34
if (!params.html.sourcePath || !params.makeBuildArtifacts) { callback() return } const oldDir = process.cwd() if (fsr.fileExists(params.html.sourcePath)) { process.chdir(params.html.sourcePath) }
Ai Example
1 2 3
const currentDirectory = process.cwd(); console.log("Current directory:", currentDirectory);
In this example, we're using process.cwd to get the current working directory of the Node.js process. We're then using console.log to output the current working directory to the console. When we run this code, we'll get output that looks something like this: javascript Copy code
23 24 25 26 27 28 29 30 31
fs.mkdirSync(STORE_PATH) } try { fs.accessSync(path.join(process.cwd(), 'portable')) STORE_PATH = process.cwd() } catch { STORE_PATH = app.getPath('userData') }
93 94 95 96 97 98 99 100 101 102
} else if ( !lt_config["run_settings"]["cypress_config_file"] && fs.existsSync(path.join(process.cwd(), "cypress.json")) ) { lt_config["run_settings"]["cypress_config_file"] = path.join( process.cwd(), "cypress.json" ); } //Set the env variables
GitHub: AlexeyAB/netron
21 22 23 24 25 26 27 28 29 30
if (!electron.app.requestSingleInstanceLock()) { electron.app.quit(); } electron.app.on('second-instance', (event, commandLine, workingDirectory) => { var currentDirectory = process.cwd(); process.chdir(workingDirectory); var open = this._parseCommandLine(commandLine); process.chdir(currentDirectory); if (!open) {
GitHub: Raval-Arth/NodeJs_pr
19 20 21 22 23 24 25 26 27 28 29 30 31
console.log("total no of configuration available is " + no_conf); const usage = process.cpuUsage(); console.log("\ncpuUsage --> " + JSON.stringify(usage)); console.log("Current working directory: ", process.cwd()); console.log("debug port is " + process.debugPort); console.log(process.env); console.log("\n");
12 13 14 15 16 17 18 19 20 21 22
let ActiveDownloads = 0; let Configuration = {}; let CertConf = {}; let ServerPort = 3000; let AssetPaths = [ process.cwd(), BasePath ]; if (fs.existsSync('./config.json')) { Configuration = JSON.parse(fs.readFileSync('./config.json')); if (Configuration['ssl'] === true) { http = require('https');
GitHub: cjoakim/azure-cosmos-db
278 279 280 281 282 283 284 285 286 287
includeForCodeDiffs(basename) { return (this.ignoreCodeFiles.includes(basename) ? false : true); } pwd() { return process.cwd(); } readLines(infile) { const data = fs.readFileSync(infile, 'UTF-8');
+ 3 other calls in file
188 189 190 191 192 193 194 195 196 197
.option(`-c, --callback, <char> Callback (default: None)`) .option(`-l, --level, <char> Logger level (default: )`) .action(async (input, output, options) => { const websitesPath = path.resolve( process.cwd(), input || options.input || process.cwd() ); const configPath = path.resolve( process.cwd(), output || options.output || process.cwd()
+ 5 other calls in file
265 266 267 268 269 270 271 272 273 274
} } }, server: process.env.CODESPACES ? 'http' : 'https', static: { directory: process.cwd() } }; }
4 5 6 7 8 9 10 11 12 13 14 15 16
console.log(process.argv); console.log(process.argv0); console.log('current working directory: ', process.cwd()) try { // Change the directory process.chdir('./data');
+ 2 other calls in file
GitHub: Matyfusari/Backend
64 65 66 67 68 69 70 71 72 73
platform: process.platform, nodeVersion: process.version, memoryTotalReserved: process.memoryUsage().rss, execPath: process.execPath, pid: process.pid, proyectPath: process.cwd(), CPUS: cpus().length } res.render('info',{ info: info }) logger.info(info)
GitHub: svidgen/wirejs-scripts
7 8 9 10 11 12 13 14 15 16 17 18
const webpack = require('webpack'); const webpackConfigure = require('./configs/webpack.config'); const WebpackDevServer = require('webpack-dev-server'); const CWD = process.cwd(); const webpackConfig = webpackConfigure(process.env, process.argv); const [nodeBinPath, scriptPath, action] = process.argv; const processes = [];
26 27 28 29 30 31 32 33 34 35
throw new Error(errMsg.toString()); } } var cd = function (dir) { var cwd = process.cwd(); if (cwd != dir) { console.log(''); console.log(`> cd ${path.relative(cwd, dir)}`); shell.cd(dir);
process.exit is the most popular function in process (513 examples)