I started Node.js in a virtual environment

Introduction

This article is recorded by a student studying JS instead of a memo. Don't expect the content.

Launch the console in a virtual environment

This time it will be done on Ubuntu, so I will start the virtual environment with iTerm2.

Where it started

  1. Virtual Box 2.Vagrant I use Ubuntu in a virtual environment that uses two software. cd ~/vagrant/ubuntu vagrant up vagrant ssh

Move to the directory where Ubuntu is installed. vagrant up is a command to start Ubuntu installed on a virtual PC, and vagrant ssh connects to SSH with the Vagrant virtual machine set.

Try using Node.js

On the console

If you enter, the console will be ready to accept js. This is a state called REPL. Describe the node.js file saved in the directory to be implemented this time below.

const n = process.argv[2] || 0;
let sum = 0;
for (let i = 1; i <= n; i++) {
  s = s + i;
}
console.log(s);

The first line is a description for using JS in strict mode.,The second line is a variable called n```process.argv[2] || 0

The above values are assigned. process.argv is Node.Get command line arguments from the js program. argv[0]Node executable file(node.exe)Full path, argv[1]Script file(.js)Because the full path of,Can store argv[2]Because.||Returns the left side if the JS logical operator OR can see the left side as true. Otherwise it returns the right side. When used with a boolean value If either of the operation targets is true,||Returns true, and if both are false, returns false.


 The third line specifies a variable called s, and the fourth and subsequent lines write a loop using a for statement. The loop continues until i is the value of the command line argument.
 Finally, display the value of s on the console and finish.

 If you write the following in the console of the virtual environment and the value is displayed, it is successful. Thank you for your hard work!!!
```node file name command line argument

What is REPL?

When the user enters one or more expressions in the REPL, the interpreter evaluates them and displays the results on the console. The statically typed language REPL allows you to enjoy the convenience of a dynamically typed language while maintaining type safety, but some REPLs installed in the integrated development environment run on the code editor. Some have full-fledged code completion similar to what they do.

What are command line arguments?

The command line is a screen operated only with the keyboard, and the arguments are the values passed to the program or function. In other words, when you say a command line argument, interpret it as a value to be passed to the program.

Recommended Posts

I started Node.js in a virtual environment
Install Django in a pipenv virtual environment
Creating a virtual environment in an Anaconda environment
virtual environment in python
Ubuntu18.04.05 Creating a python virtual environment in LTS
Create a virtual environment with conda in Python
Work in a virtual environment with Python virtualenv.
Escape from Python's virtual environment ~ A story about being trapped in a virtual environment I created ~
Building a Python virtual environment
I participated in competitive programming in a week after I started programming
I tried the super-resolution algorithm "PULSE" in a Windows environment
[Django3] Display a web page in Django3 + WSL + Python virtual environment
A note on how to load a virtual environment in PyCharm
How to develop in a virtual environment of Python [Memo]
I just built a virtual environment with AWS lambda layer
I get a KeyError in pyclustering.xmeans
Create a virtual environment with Python!
From installing Ansible to building a Python environment in Vagrant's virtual environment
I want to print in a comprehension
I made a payroll program in Python!
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
I want to build a Python environment
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
Create a virtual environment with Python_Mac version
I installed Kivy on a Mac environment
I tried putting virtualenv in Cygwin environment
I built a TensorFlow environment on windows10
Build a python virtual environment with pyenv
I created a password tool in Python.
Add a Python virtual environment to VSCode
Use WebDAV in a Portable Docker environment
Build a LAMP environment in a very short time
Create a Vim + Python test environment in 1 minute
What I was addicted to when creating a web application in a windows environment
How to share a virtual environment [About requirements.txt]
When I get a chromedriver error in Selenium
How to create a Python virtual environment (venv)
System switching occurs in a CentOS 7 cluster environment
A memo that I wrote a quicksort in Python
Use the latest pip in a virtualenv environment
I want to create a window in Python
I tried playing a typing game in Python
I wrote a class in Python3 and Java
Beginner virtual environment
When I tried to create a virtual environment with Python, it didn't work
I created a Dockerfile for Django's development environment
[Memo] I tried a pivot table in Python
Build a Django environment with Vagrant in 5 minutes
[Azure] I tried to create a Linux virtual machine in Azure of Microsoft Learn
Create a Django project and application in a Python virtual environment and start the server
[Memo] Build a virtual environment with Pyenv + anaconda
I wrote a design pattern in kotlin Prototype
Set a fixed IP in the Linux environment
[Python] Web development preparation (building a virtual environment)
Build a simple Python virtual environment without pyenv
Build a virtual environment with pyenv and venv
Think about building a Python 3 environment in a Mac environment
Flow of creating a virtual environment with Anaconda
I tried adding a Python3 module in C