2022-10-21 17:16:00 +02:00
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home ](./index.md ) > [bitburner ](./bitburner.md ) > [NS ](./bitburner.ns.md )
## NS interface
Collection of all functions passed to scripts
2023-02-11 19:18:50 +01:00
**Signature:**
2022-10-21 17:16:00 +02:00
```typescript
export interface NS
```
## Remarks
2023-04-28 20:19:30 +02:00
< b > Basic usage example:< / b >
2022-10-21 17:16:00 +02:00
2023-04-28 20:19:30 +02:00
```js
2022-10-21 17:16:00 +02:00
export async function main(ns) {
// Basic ns functions can be accessed on the ns object
ns.getHostname();
// Some related functions are gathered under a sub-property of the ns object
ns.stock.getPrice();
2023-04-28 20:19:30 +02:00
// Most functions that return a promise need to be awaited.
2022-10-21 17:16:00 +02:00
await ns.hack('n00dles');
}
```
2023-04-28 20:19:30 +02:00
[ns2 in-game docs ](https://bitburner-official.readthedocs.io/en/latest/netscript/netscriptjs.html ) < hr > For (deprecated) .script usage, see: [ns1 in-game docs ](https://bitburner-official.readthedocs.io/en/latest/netscript/netscript1.html ) < hr >
2022-10-21 17:16:00 +02:00
## Properties
2023-02-11 19:18:50 +01:00
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [args ](./bitburner.ns.args.md ) | < code > readonly</ code > | (string \| number \| boolean)\[\] | Arguments passed into the script. |
2023-03-08 07:39:05 +01:00
| [bladeburner ](./bitburner.ns.bladeburner.md ) | < code > readonly</ code > | [Bladeburner ](./bitburner.bladeburner.md ) | Namespace for bladeburner functions. Contains spoilers. |
2023-02-11 19:18:50 +01:00
| [codingcontract ](./bitburner.ns.codingcontract.md ) | < code > readonly</ code > | [CodingContract ](./bitburner.codingcontract.md ) | Namespace for codingcontract functions. |
2023-03-08 07:39:05 +01:00
| [corporation ](./bitburner.ns.corporation.md ) | < code > readonly</ code > | [Corporation ](./bitburner.corporation.md ) | Namespace for corporation functions. Contains spoilers. |
2023-02-11 19:18:50 +01:00
| [enums ](./bitburner.ns.enums.md ) | | [NSEnums ](./bitburner.nsenums.md ) | |
| [formulas ](./bitburner.ns.formulas.md ) | < code > readonly</ code > | [Formulas ](./bitburner.formulas.md ) | Namespace for formulas functions. |
2023-03-08 07:39:05 +01:00
| [gang ](./bitburner.ns.gang.md ) | < code > readonly</ code > | [Gang ](./bitburner.gang.md ) | Namespace for gang functions. Contains spoilers. |
| [grafting ](./bitburner.ns.grafting.md ) | < code > readonly</ code > | [Grafting ](./bitburner.grafting.md ) | Namespace for grafting functions. Contains spoilers. |
| [hacknet ](./bitburner.ns.hacknet.md ) | < code > readonly</ code > | [Hacknet ](./bitburner.hacknet.md ) | Namespace for hacknet functions. Some of this API contains spoilers. |
| [infiltration ](./bitburner.ns.infiltration.md ) | < code > readonly</ code > | [Infiltration ](./bitburner.infiltration.md ) | Namespace for infiltration functions. |
2023-02-11 19:18:50 +01:00
| [pid ](./bitburner.ns.pid.md ) | < code > readonly</ code > | number | The current script's PID |
2023-03-08 07:39:05 +01:00
| [singularity ](./bitburner.ns.singularity.md ) | < code > readonly</ code > | [Singularity ](./bitburner.singularity.md ) | Namespace for singularity functions. Contains spoilers. |
| [sleeve ](./bitburner.ns.sleeve.md ) | < code > readonly</ code > | [Sleeve ](./bitburner.sleeve.md ) | Namespace for sleeve functions. Contains spoilers. |
| [stanek ](./bitburner.ns.stanek.md ) | < code > readonly</ code > | [Stanek ](./bitburner.stanek.md ) | Namespace for stanek functions. Contains spoilers. |
2023-02-11 19:18:50 +01:00
| [stock ](./bitburner.ns.stock.md ) | < code > readonly</ code > | [TIX ](./bitburner.tix.md ) | Namespace for stock functions. |
2023-03-08 07:39:05 +01:00
| [ui ](./bitburner.ns.ui.md ) | < code > readonly</ code > | [UserInterface ](./bitburner.userinterface.md ) | Namespace for user interface functions. |
2022-10-21 17:16:00 +02:00
## Methods
| Method | Description |
| --- | --- |
| [alert(msg) ](./bitburner.ns.alert.md ) | Open up a message box. |
2023-04-28 20:19:30 +02:00
| [asleep(millis) ](./bitburner.ns.asleep.md ) | Suspends the script for n milliseconds. Doesn't block with concurrent calls. |
2022-10-21 17:16:00 +02:00
| [atExit(f) ](./bitburner.ns.atexit.md ) | Add callback function when the script dies |
| [brutessh(host) ](./bitburner.ns.brutessh.md ) | Runs BruteSSH.exe on a server. |
| [clear(handle) ](./bitburner.ns.clear.md ) | Clear data from a file. |
| [clearLog() ](./bitburner.ns.clearlog.md ) | Clears the script’ s logs. |
| [clearPort(handle) ](./bitburner.ns.clearport.md ) | Clear data from a port. |
| [closeTail(pid) ](./bitburner.ns.closetail.md ) | Close the tail window of a script. |
| [deleteServer(host) ](./bitburner.ns.deleteserver.md ) | Delete a purchased server. |
| [disableLog(fn) ](./bitburner.ns.disablelog.md ) | Disables logging for the given function. |
| [enableLog(fn) ](./bitburner.ns.enablelog.md ) | Enable logging for a certain function. |
2023-03-21 23:54:49 +01:00
| [exec(script, hostname, threadOrOptions, args) ](./bitburner.ns.exec.md ) | Start another script on any server. |
2022-10-21 17:16:00 +02:00
| [exit() ](./bitburner.ns.exit.md ) | Terminates the current script immediately. |
| [fileExists(filename, host) ](./bitburner.ns.fileexists.md ) | Check if a file exists. |
| [flags(schema) ](./bitburner.ns.flags.md ) | Parse command line flags. |
2023-02-11 19:18:50 +01:00
| [formatNumber(n, fractionalDigits, suffixStart, isInteger) ](./bitburner.ns.formatnumber.md ) | Format a number. |
2023-02-19 21:24:27 +01:00
| [formatPercent(n, fractionalDigits, multStart) ](./bitburner.ns.formatpercent.md ) | Format a number as a percentage. |
2023-02-11 19:18:50 +01:00
| [formatRam(n, fractionalDigits) ](./bitburner.ns.formatram.md ) | Format a number as an amount of ram. |
2022-10-21 17:16:00 +02:00
| [ftpcrack(host) ](./bitburner.ns.ftpcrack.md ) | Runs FTPCrack.exe on a server. |
2022-11-20 18:07:22 +01:00
| [getBitNodeMultipliers(n, lvl) ](./bitburner.ns.getbitnodemultipliers.md ) | Get the current Bitnode multipliers. |
2022-10-21 17:16:00 +02:00
| [getFavorToDonate() ](./bitburner.ns.getfavortodonate.md ) | Returns the amount of Faction favor required to be able to donate to a faction. |
2023-05-26 13:46:08 +02:00
| [getFunctionRamCost(name) ](./bitburner.ns.getfunctionramcost.md ) | Get the ram cost of a netscript function. |
2022-10-21 17:16:00 +02:00
| [getGrowTime(host) ](./bitburner.ns.getgrowtime.md ) | Get the execution time of a grow() call. |
| [getHackingLevel() ](./bitburner.ns.gethackinglevel.md ) | Returns the player’ s current hacking level. |
| [getHackingMultipliers() ](./bitburner.ns.gethackingmultipliers.md ) | Get hacking related multipliers. |
| [getHacknetMultipliers() ](./bitburner.ns.gethacknetmultipliers.md ) | Get hacknet related multipliers. |
| [getHackTime(host) ](./bitburner.ns.gethacktime.md ) | Get the execution time of a hack() call. |
| [getHostname() ](./bitburner.ns.gethostname.md ) | Returns a string with the hostname of the server that the script is running on. |
2022-11-20 18:07:22 +01:00
| [getMoneySources() ](./bitburner.ns.getmoneysources.md ) | Get information about the sources of income for this run. |
2022-10-21 17:16:00 +02:00
| [getPlayer() ](./bitburner.ns.getplayer.md ) | Get information about the player. |
2023-02-28 01:54:04 +01:00
| [getPortHandle(portNumber) ](./bitburner.ns.getporthandle.md ) | Get all data on a port. |
2022-10-21 17:16:00 +02:00
| [getPurchasedServerCost(ram) ](./bitburner.ns.getpurchasedservercost.md ) | Get cost of purchasing a server. |
| [getPurchasedServerLimit() ](./bitburner.ns.getpurchasedserverlimit.md ) | Returns the maximum number of servers you can purchase. |
| [getPurchasedServerMaxRam() ](./bitburner.ns.getpurchasedservermaxram.md ) | Returns the maximum RAM that a purchased server can have. |
| [getPurchasedServers() ](./bitburner.ns.getpurchasedservers.md ) | Returns an array with the hostnames of all of the servers you have purchased. |
| [getPurchasedServerUpgradeCost(hostname, ram) ](./bitburner.ns.getpurchasedserverupgradecost.md ) | Get cost of upgrading a purchased server to the given ram. |
| [getRecentScripts() ](./bitburner.ns.getrecentscripts.md ) | Get an array of recently killed scripts across all servers. |
2023-04-25 11:22:36 +02:00
| [getResetInfo() ](./bitburner.ns.getresetinfo.md ) | Get information about resets. |
2022-10-21 17:16:00 +02:00
| [getRunningScript(filename, hostname, args) ](./bitburner.ns.getrunningscript.md ) | Get general info about a running script. |
| [getScriptExpGain(script, host, args) ](./bitburner.ns.getscriptexpgain.md ) | Get the exp gain of a script. |
| [getScriptIncome(script, host, args) ](./bitburner.ns.getscriptincome.md ) | Get the income of a script. |
| [getScriptLogs(fn, host, args) ](./bitburner.ns.getscriptlogs.md ) | Get all the logs of a script. |
| [getScriptName() ](./bitburner.ns.getscriptname.md ) | Returns the current script name. |
| [getScriptRam(script, host) ](./bitburner.ns.getscriptram.md ) | Get the ram cost of a script. |
| [getServer(host) ](./bitburner.ns.getserver.md ) | Returns a server object for the given server. Defaults to the running script's server if host is not specified. |
2023-02-21 15:44:18 +01:00
| [getServerBaseSecurityLevel(host) ](./bitburner.ns.getserverbasesecuritylevel.md ) | Get the base security level of a server. |
2022-10-21 17:16:00 +02:00
| [getServerGrowth(host) ](./bitburner.ns.getservergrowth.md ) | Get a server growth parameter. |
2022-11-20 18:07:22 +01:00
| [getServerMaxMoney(host) ](./bitburner.ns.getservermaxmoney.md ) | Get the maximum money available on a server. |
| [getServerMaxRam(host) ](./bitburner.ns.getservermaxram.md ) | Get the maximum amount of RAM on a server. |
2022-10-21 17:16:00 +02:00
| [getServerMinSecurityLevel(host) ](./bitburner.ns.getserverminsecuritylevel.md ) | Returns the minimum security level of the target server. |
| [getServerMoneyAvailable(host) ](./bitburner.ns.getservermoneyavailable.md ) | Get money available on a server. |
| [getServerNumPortsRequired(host) ](./bitburner.ns.getservernumportsrequired.md ) | Returns the number of open ports required to successfully run NUKE.exe on the specified server. |
| [getServerRequiredHackingLevel(host) ](./bitburner.ns.getserverrequiredhackinglevel.md ) | Returns the required hacking level of the target server. |
| [getServerSecurityLevel(host) ](./bitburner.ns.getserversecuritylevel.md ) | Get server security level. |
| [getServerUsedRam(host) ](./bitburner.ns.getserverusedram.md ) | Get the used RAM on a server. |
| [getSharePower() ](./bitburner.ns.getsharepower.md ) | Calculate your share power. Based on all the active share calls. |
| [getTimeSinceLastAug() ](./bitburner.ns.gettimesincelastaug.md ) | Returns the amount of time in milliseconds that have passed since you last installed Augmentations. |
2022-11-20 18:07:22 +01:00
| [getTotalScriptExpGain() ](./bitburner.ns.gettotalscriptexpgain.md ) | Get the exp gain of all scripts. |
| [getTotalScriptIncome() ](./bitburner.ns.gettotalscriptincome.md ) | Get the income of all scripts. |
2022-10-21 17:16:00 +02:00
| [getWeakenTime(host) ](./bitburner.ns.getweakentime.md ) | Get the execution time of a weaken() call. |
2022-11-20 18:07:22 +01:00
| [grow(host, opts) ](./bitburner.ns.grow.md ) | Spoof money in a server's bank account, increasing the amount available. |
2023-02-17 09:14:20 +01:00
| [growthAnalyze(host, multiplier, cores) ](./bitburner.ns.growthanalyze.md ) | Calculate the number of grow threads needed for a given multiplicative growth factor. |
2023-02-28 15:57:02 +01:00
| [growthAnalyzeSecurity(threads, hostname, cores) ](./bitburner.ns.growthanalyzesecurity.md ) | Calculate the security increase for a number of grow threads. |
2022-11-20 18:07:22 +01:00
| [hack(host, opts) ](./bitburner.ns.hack.md ) | Steal a server's money. |
2022-10-21 17:16:00 +02:00
| [hackAnalyze(host) ](./bitburner.ns.hackanalyze.md ) | Get the part of money stolen with a single thread. |
| [hackAnalyzeChance(host) ](./bitburner.ns.hackanalyzechance.md ) | Get the chance of successfully hacking a server. |
2022-11-20 18:07:22 +01:00
| [hackAnalyzeSecurity(threads, hostname) ](./bitburner.ns.hackanalyzesecurity.md ) | Get the security increase for a number of threads. |
2023-02-17 09:14:20 +01:00
| [hackAnalyzeThreads(host, hackAmount) ](./bitburner.ns.hackanalyzethreads.md ) | Calculate the decimal number of threads needed to hack a specified amount of money from a target host. |
2022-11-20 18:07:22 +01:00
| [hasRootAccess(host) ](./bitburner.ns.hasrootaccess.md ) | Check if you have root access on a server. |
| [hasTorRouter() ](./bitburner.ns.hastorrouter.md ) | Returns whether the player has access to the darkweb. |
2022-10-21 17:16:00 +02:00
| [httpworm(host) ](./bitburner.ns.httpworm.md ) | Runs HTTPWorm.exe on a server. |
| [isLogEnabled(fn) ](./bitburner.ns.islogenabled.md ) | Checks the status of the logging for the given function. |
| [isRunning(script, host, args) ](./bitburner.ns.isrunning.md ) | Check if a script is running. |
2023-02-14 03:50:38 +01:00
| [kill(pid) ](./bitburner.ns.kill.md ) | Terminate the script with the provided PID. |
2023-04-28 00:21:06 +02:00
| [kill(filename, hostname, args) ](./bitburner.ns.kill_1.md ) | Terminate the script(s) with the provided filename, hostname, and script arguments. |
2022-10-21 17:16:00 +02:00
| [killall(host, safetyguard) ](./bitburner.ns.killall.md ) | Terminate all scripts on a server. |
2023-03-07 14:04:08 +01:00
| [ls(host, substring) ](./bitburner.ns.ls.md ) | List files on a server. |
2022-11-20 18:07:22 +01:00
| [moveTail(x, y, pid) ](./bitburner.ns.movetail.md ) | Move a tail window. |
2022-10-21 17:16:00 +02:00
| [mv(host, source, destination) ](./bitburner.ns.mv.md ) | Move a file on the target server. |
2023-04-25 11:22:36 +02:00
| [nFormat(n, format) ](./bitburner.ns.nformat.md ) | Format a number using the numeral library. This function is deprecated and will be removed in 2.4. |
2022-10-21 17:16:00 +02:00
| [nuke(host) ](./bitburner.ns.nuke.md ) | Runs NUKE.exe on a server. |
2023-02-28 01:54:04 +01:00
| [peek(portNumber) ](./bitburner.ns.peek.md ) | Get a copy of the data from a port without popping it. |
2022-11-20 18:07:22 +01:00
| [print(args) ](./bitburner.ns.print.md ) | Prints one or more values or variables to the script’ s logs. |
2022-10-21 17:16:00 +02:00
| [printf(format, args) ](./bitburner.ns.printf.md ) | Prints a formatted string to the script’ s logs. |
2023-07-08 00:23:26 +02:00
| [printRaw(node) ](./bitburner.ns.printraw.md ) | Prints a ReactNode to the script logs. |
2022-10-21 17:16:00 +02:00
| [prompt(txt, options) ](./bitburner.ns.prompt.md ) | Prompt the player with an input modal. |
| [ps(host) ](./bitburner.ns.ps.md ) | List running scripts on a server. |
| [purchaseServer(hostname, ram) ](./bitburner.ns.purchaseserver.md ) | Purchase a server. |
| [read(filename) ](./bitburner.ns.read.md ) | Read content of a file. |
2023-02-28 01:54:04 +01:00
| [readPort(portNumber) ](./bitburner.ns.readport.md ) | Read data from a port. |
2022-10-21 17:16:00 +02:00
| [relaysmtp(host) ](./bitburner.ns.relaysmtp.md ) | Runs relaySMTP.exe on a server. |
| [renamePurchasedServer(hostname, newName) ](./bitburner.ns.renamepurchasedserver.md ) | Rename a purchased server. |
2022-11-20 18:07:22 +01:00
| [resizeTail(width, height, pid) ](./bitburner.ns.resizetail.md ) | Resize a tail window. |
2022-10-21 17:16:00 +02:00
| [rm(name, host) ](./bitburner.ns.rm.md ) | Delete a file. |
2023-03-21 23:54:49 +01:00
| [run(script, threadOrOptions, args) ](./bitburner.ns.run.md ) | Start another script on the current server. |
2022-10-21 17:16:00 +02:00
| [scan(host) ](./bitburner.ns.scan.md ) | Get the list of servers connected to a server. |
| [scp(files, destination, source) ](./bitburner.ns.scp.md ) | Copy file between servers. |
| [scriptKill(script, host) ](./bitburner.ns.scriptkill.md ) | Kill all scripts with a filename. |
| [scriptRunning(script, host) ](./bitburner.ns.scriptrunning.md ) | Check if any script with a filename is running. |
| [serverExists(host) ](./bitburner.ns.serverexists.md ) | Returns a boolean denoting whether or not the specified server exists. |
2023-05-26 14:07:37 +02:00
| [setTitle(title, pid) ](./bitburner.ns.settitle.md ) | Set the title of the tail window of a script. |
2023-03-21 23:54:49 +01:00
| [share() ](./bitburner.ns.share.md ) | Share the server's ram with your factions. |
2022-10-21 17:16:00 +02:00
| [sleep(millis) ](./bitburner.ns.sleep.md ) | Suspends the script for n milliseconds. |
2023-03-21 23:54:49 +01:00
| [spawn(script, threadOrOptions, args) ](./bitburner.ns.spawn.md ) | Terminate current script and start another in 10 seconds. |
2022-10-21 17:16:00 +02:00
| [sprintf(format, args) ](./bitburner.ns.sprintf.md ) | Format a string. |
| [sqlinject(host) ](./bitburner.ns.sqlinject.md ) | Runs SQLInject.exe on a server. |
| [tail(fn, host, args) ](./bitburner.ns.tail.md ) | Open the tail window of a script. |
2022-11-20 18:07:22 +01:00
| [tFormat(milliseconds, milliPrecision) ](./bitburner.ns.tformat.md ) | Format time to a readable string. |
2022-10-21 17:16:00 +02:00
| [toast(msg, variant, duration) ](./bitburner.ns.toast.md ) | Queue a toast (bottom-right notification). |
| [tprint(args) ](./bitburner.ns.tprint.md ) | Prints one or more values or variables to the Terminal. |
| [tprintf(format, values) ](./bitburner.ns.tprintf.md ) | Prints a raw value or a variable to the Terminal. |
2023-07-08 00:23:26 +02:00
| [tprintRaw(node) ](./bitburner.ns.tprintraw.md ) | Prints a ReactNode to the terminal. |
2023-02-28 01:54:04 +01:00
| [tryWritePort(portNumber, data) ](./bitburner.ns.trywriteport.md ) | Attempt to write to a port. |
2022-11-20 18:07:22 +01:00
| [upgradePurchasedServer(hostname, ram) ](./bitburner.ns.upgradepurchasedserver.md ) | Upgrade a purchased server's RAM. |
2022-10-21 17:16:00 +02:00
| [vsprintf(format, args) ](./bitburner.ns.vsprintf.md ) | Format a string with an array of arguments. |
2022-11-20 18:07:22 +01:00
| [weaken(host, opts) ](./bitburner.ns.weaken.md ) | Reduce a server's security level. |
2022-10-21 17:16:00 +02:00
| [weakenAnalyze(threads, cores) ](./bitburner.ns.weakenanalyze.md ) | Predict the effect of weaken. |
| [wget(url, target, host) ](./bitburner.ns.wget.md ) | Download a file from the internet. |
| [write(filename, data, mode) ](./bitburner.ns.write.md ) | Write data to a file. |
2023-02-28 01:54:04 +01:00
| [writePort(portNumber, data) ](./bitburner.ns.writeport.md ) | Write data to a port. |
2022-10-21 17:16:00 +02:00