search
HomeWeb Front-endCSS TutorialA Deep Look at the Command Line

A Deep Look at the Command Line

We have learned about the meaning of npm, and its role and position in web development. Next, we will take some time to understand the command line, as it is how we interact with npm.

Guide Chapter

  1. Who is this guide for?
  2. What does "npm" mean?
  3. What is the command line? (Your current location!)
  4. What is Node?
  5. What is a package manager?
  6. How to install npm?
  7. How to install npm package?
  8. What is the npm command?
  9. How to install an existing npm project?

Command line overview

The command line is a place where we can enter (unexpectedly) commands that will be executed directly by our computer. It's extremely fast and has higher administrator privileges than most applications that try to handle the command line for you. Need to install something on the system, or update it? The command line can do this, let alone uninstall them. Even server-side languages ​​can run on the command line, opening up a range of tools and development techniques.

For these reasons, the command line is considered an indispensable tool for many developers. Even if you are not a developer, you are likely to have encountered the command line at some point. Maybe you visited it when you opened a terminal application in MacOS. Maybe you're using a command line built directly into the code editor - VS Code and many other code editors come with an integrated terminal. Maybe you've even come across third-party terminal applications like iTerm or Hyper.

If you've used a terminal, most of your command line usage so far may just be typing (or pasting) the commands someone else gave you. This is good; it's usually how we get things done.

But let's take a moment to understand what the command line is and why it's used so widely.

Command Line and Terminal

"Command Line" and "Terminal" are technically two different and very different things, but are often used interchangeably. You may also hear that the command line is called "shell", or see that it is abbreviated as "CLI", which is the abbreviation for "Command Line Interface".

Putting aside those nitpicking differences, these terms are often used to mean almost the same. So, to be as simple as possible, I will use them interchangeably from now on.

Open the command line

No matter why you want to call it, you might think of the command line as that scary-looking window, perhaps a black background and white (sometimes green) text where you can type commands your computer seems to understand, even if you don't.

Depending on where and how you work on the command line, one unremarkable thing you might notice is the dollar sign character $, which is displayed on the first line you can start typing. You may even see it in other articles or documents.

It is usually a convention to use the $ character as the prefix of the command - but this is indeed a confusing convention. This is because there is no need to type it. It is not actually part of the command. Instead, $ represents a command to run in the terminal.

So here is the first rule about using the command line: If you find yourself typing or copying a directive containing the $ character, know that you don't need to include it in your work; the terminal already includes it.

 <code>## 无需复制$ $ npm run build</code>

You may see other characters starting a line instead of $, such as >, _, or even arrows. Again, whatever it is, it almost certainly isn't meant to be typed directly or pasted into the command line. Whether the documentation or other tutorial should contain a line of starting characters is a completely different discussion (Chris has discussed it in detail). Either way, it can be confusing, so I want to make sure this is pointed out.

What can the command line do?

Movies and TV shows often portray terminals as quick typing tools used by hackers in dark, secluded rooms. Part of this is simply because it provides good entertainment for people who may not know the difference between the real terminal and the cascade letters in The Matrix. (Neither should they; I can’t tell if the surgery depicted on the TV show is accurate and leave this distinction to the professional with complete satisfaction.)

But the command line is not entirely used to write code. As the name "command line" implies, it is used to write commands . I think you can say that all encodings are commands to some extent, so this is undoubtedly a blurred line. But generally speaking, the code in the terminal is written differently than in the code editor. Instead, you use a terminal to direct your computer to run commands you want it to run immediately .

Advantages of the command line

You might be wondering why developers like to work on the command line in the first place. You might prefer a nice app or graphical user interface (GUI for short, sometimes pronounced as "gooey"), where you can see all the options and intuitively find the best ones. This is absolutely fine, we will discuss the GUI in this chapter and provide some examples.

Many developers feel this way, even if it doesn't look like it. However, working on the command line brings some advantages that visual applications are not always easy to replicate.

It gives you God-like system permissions

The command line is what computer science workers call a "privileged environment." This may sound like it refers to the Yale fraternity, but it simply means it's a place that has little to no limit on what you can do; a place without guardrails.

This is where the command line’s reputation comes from—whatever command you type, it will be executed immediately as long as it works, and is often irreversible. It is able to interact with hidden files that the operating system tries to block you from editing. You can access anything in the system. You can even interact with similar core files on remote servers—we all know the proverb, great responsibility comes with this power.

It may be helpful to treat the command line as a lazy security guard. It assumes that you always know what you are doing and lets you go directly through the entrance. It's really a bit of a risky one, yes, but it also makes it very powerful and perfect for certain tasks and projects.

It's extremely fast

Another advantage of the command line over a typical application is that it is very fast .

This is not always the case; the speed of the command line is often exaggerated and depends to a large extent on the task in question. But when it does get faster, it can usually be many times faster. In addition, the real flash of the command line is often where the code project needs the most speed, that is, downloading and creating files.

As we will see in other chapters of this guide, a key part of npm is installing things on your machine (usually in the specified folder of the project you are working on). This is why the command line works well with package managers (we will also understand what this means) like npm – it downloads and transfers files between computers – is usually much faster, much faster, than using a browser to do this.

The command line enables npm to generate large amounts of files at incredible speeds. The ability to run a single command at lightning speed to install, update or delete these files simultaneously makes the terminal the fastest and most effective tool for many jobs.

It can do things that other languages ​​cannot do

Another reason why working in a terminal is that many of the tools you may want to use in your project can be used without any additional settings.

But let's review it a little.

When you hear the phrase "server-side language", you may think of PHP, Ruby, or Java. Perhaps a new member of the field, such as Rust or Go. You may even already know that Node belongs to the list, but if not, forgive me a little bit ahead of time.

Anyway, when most people think of these server-side languages, they tend to think of a web server that waits for a request and then responds to them. For example, WordPress is idle until it receives a request to start PHP. When you send a new tweet, that is a request to the Twitter server, which eventually arrives at the Ruby method in Rails.

Server-side languages ​​are considered to be more powerful than web languages. HTML, CSS, and JavaScript are great, but they can't handle file systems, send emails, process images, issue system commands, interact with the operating system, or run scheduled tasks; and many other things that an application or website may need to do. By default, JavaScript in the browser won't even run unless someone is actively viewing the web page in the browser.

Server-side languages ​​are generally considered to be a powerful engine behind more powerful applications and software. And, in many cases, this is accurate. But let's take a moment to realize that in order to run the code, your machine is a server . Not a web server, although (it could be one, but that would be weird and probably unwise). But it's a server anyway.

You can install and run any of the server-side languages ​​we mentioned, maybe you have done so at some point (or at least tried). You might have PHP installed so that you can run WordPress (although there are better ways to do this now), or you might have Ruby installed so that you can follow some tutorials on Rails, to name a few.

Or, maybe not. Maybe you have never installed the entire programming language before. Either way, just know that these languages ​​run on the server , not on the web browser - for that, your machine is a server.

Apart from that, many of the tools you may want to use in your development workflow—such as Sass for compiling CSS—actually run on a server-side language. So use the command line to place you where all the most powerful tools are available at any time.

Use an application instead of command line

We briefly introduce the GUI before this article. It is worth noting that some command line tasks have corresponding GUIs that make the command line work more intuitive and programmatic.

Good examples include GitHub Desktop (for managing code repositories) and CodeKit (for processing, bundling, and compiling assets), although the Source Code Management tab in VS Code also qualifies. Even though these GUIs are often focused on specific tasks, they allow you to complete tasks in real application windows outside of the terminal window through a beautiful visual user interface.

GUI is great as an option, and although I've been used to working on the command line over the years, I still want to have more GUIs to do the things that command-line makes possible – for my own convenience and lowering the barriers to entry for new developers.

However, the reason I believe there are no more such applications is speed. Building a command line interface (CLI) is much faster and easier than building a complete application, usually several orders of magnitude faster. So if we want to get something good today, the command line is usually where we need to go.

Next steps

We just spent some time getting familiar with the command line. Even if the command line is not npm specific , it is the core of working with npm. It is the interface we tell the system what to do, and it gives us amazing ability to complete a large number of tasks at an extremely fast speed at the system or server level. As a package manager, npm is responsible for installing, updating, and deleting files (and other things) for web projects. The command line is the way we communicate with npm to do all of these operations.

Next, we will break down in more detail what npm is by focusing on the first letter in the abbreviation: "n" stands for Node. What is that, why is it in the name? This is what we are paying attention to next.

← Chapter 2 Chapter 4 →

The above is the detailed content of A Deep Look at the Command Line. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Anchor Positioning Just Don't Care About Source OrderAnchor Positioning Just Don't Care About Source OrderApr 29, 2025 am 09:37 AM

The fact that anchor positioning eschews HTML source order is so CSS-y because it's another separation of concerns between content and presentation.

What does margin: 40px 100px 120px 80px signify?What does margin: 40px 100px 120px 80px signify?Apr 28, 2025 pm 05:31 PM

Article discusses CSS margin property, specifically "margin: 40px 100px 120px 80px", its application, and effects on webpage layout.

What are the different CSS border properties?What are the different CSS border properties?Apr 28, 2025 pm 05:30 PM

The article discusses CSS border properties, focusing on customization, best practices, and responsiveness. Main argument: border-radius is most effective for responsive designs.

What are CSS backgrounds, list the properties?What are CSS backgrounds, list the properties?Apr 28, 2025 pm 05:29 PM

The article discusses CSS background properties, their uses in enhancing website design, and common mistakes to avoid. Key focus is on responsive design using background-size.

What are CSS HSL Colors?What are CSS HSL Colors?Apr 28, 2025 pm 05:28 PM

Article discusses CSS HSL colors, their use in web design, and advantages over RGB. Main focus is on enhancing design and accessibility through intuitive color manipulation.

How can we add comments in CSS?How can we add comments in CSS?Apr 28, 2025 pm 05:27 PM

The article discusses the use of comments in CSS, detailing single-line and multi-line comment syntaxes. It argues that comments enhance code readability, maintainability, and collaboration, but may impact website performance if not managed properly.

What are CSS Selectors?What are CSS Selectors?Apr 28, 2025 pm 05:26 PM

The article discusses CSS Selectors, their types, and usage for styling HTML elements. It compares ID and class selectors and addresses performance issues with complex selectors.

Which type of CSS holds the highest priority?Which type of CSS holds the highest priority?Apr 28, 2025 pm 05:25 PM

The article discusses CSS priority, focusing on inline styles having the highest specificity. It explains specificity levels, overriding methods, and debugging tools for managing CSS conflicts.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool