npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

windows-cmd

v1.0.1

Published

Execute windows command via code.

Downloads

5

Readme

windows-cmd

npm license NPM Version Build Status Dependency Status

Execute windows command via code. All functions is asynchronous.

If you have any question, issue or bug report feel free to ask.

Table of content


Installation

via npm:

npm i -S windows-cmd

Usage

const cmd = require('windows-cmd')

checkEnv(variable)

asynchronous function

Check if environment variable exists

  • {string} variable - environment variable name
try {
    await cmd.checkEnv('PATH') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

checkEnvValue(variable, value)

asynchronous function

Check if value exists in environment variable

  • {string} variable - environment variable name

  • {string} value - value of environment variable

try {
    await cmd.checkEnvValue('PATH', 'C:\\Python27') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

listEnvValues(variable)

asynchronous function

List values of environment variable

  • {string} variable - environment variable name
try {
    await cmd.listEnvValues('PATH') // > returns a string
} catch (err) {
    console.log(err.message) // => windows error
}

Result:

PATH=C:\Users\Desenvolvimento\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files (x86)\oracle-instant-client;C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\Borland\Delphi7\Bin;C:\Program Files (x86)\Borland\Delphi7\Projects\Bpl;C:\totvs\CorporeRM\API;C:\app\Desenvolvimento\product\11.2.0\dbhome_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs;C:\Users\Desenvolvimento\AppData\Local\Programs\Python\Python37-32\Scripts;C:\Users\Desenvolvimento\AppData\Local\Programs\Python\Python37;C:\Users\Desenvolvimento\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

setSystemEnv(variable, value)

asynchronous function

Add a new value to the system environment variable. If the variable does not exist it will be createds

  • {string} variable - environment variable name

  • {string} value - value of environment variable

try {
    await cmd.setSystemEnv('PATH', 'C\\Program Files (x86)\\myapp\\bin') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

setUserEnv(variable, value)

asynchronous function

Add a new value to the user environment variable. If the variable does not exist it will be createds

  • {string} variable - environment variable name

  • {string} value - value of environment variable

try {
    await cmd.setUserEnv('PATH', 'C\\Program Files (x86)\\myapp\\bin') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

checkFile(filePath, fileName)

asynchronous function

Check if file/folder exists

  • {string} filePath - path to check

  • {string} fileName - file name

try {
    await cmd.checkFile('./pdf/', 'my-pdf.pdf') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

listFile(folderPath)

asynchronous function

List all folder and files

  • {string} folderPath - path to list
try {
    await cmd.listFile('./my-folder/') // => returns a string
} catch (err) {
    console.log(err.message) // => windows error
}

Result:

19/07/2019  15:47    <DIR>          .
19/07/2019  15:47    <DIR>          ..
19/07/2019  15:46                 0 file1.txt
19/07/2019  15:46                 0 file2.txt
19/07/2019  15:47                 0 file3.pdf
               3 arquivo(s)              0 bytes
               2 pasta(s)   31.755.882.496 bytes disponíveis

copyFile(filePath, toPath)

asynchronous function

Copy file/folder

  • {string} filePath - file path

  • {string} toPath - path to paste

try {
    // Copy my-pdf.pdf and paste it in paste-folder
    await cmd.copyFile('./pdf/my-pdf.pdf', './paste-folder/') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

mkDir(folderPath)

asynchronous function

Create a folder

  • {string} folderPath - folder path with name
try {
    // create logs folder
    await cmd.mkDir('./my-app/logs') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

checkWinrar()

asynchronous function

Checks if winrar is installed

try {
    await cmd.checkWinrar() // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

winrarExtract(filePath, toPath)

asynchronous function

Extract .rar file

  • {string} filePath - file path

  • {string} toPath - path to extract

try {
    await cmd.winrarExtract('./file.rar', 'C\\Program Files (x86)\\extract-folder') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

exec(command)

asynchronous function

Execute windows command

  • {string} command - cmd command
try {
    await cmd.exec('mkdir myFolder') // => true or false
} catch (err) {
    console.log(err.message) // => windows error
}

Changelog

See the update notes at CHANGELOG.

License

MIT License

Copyright ® 2019 Victor Gianvechio

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.