[JAVA] Used from the introduction of Node.js in WSL environment

Introduction

It is mainly used as a memorandum for posters. Introduce Node.js, which is useful for creating the Web.

environment

Install on wsl (Windows Subsystem for Linux).

Editor: VSCode
Shell: bash version 4.4.20
Ubuntu: 18.04.4 LTS

table of contents

  1. Introduction of nvm [>>](Introduction of # 1 nvm)
  2. Introduction of Node.js [>>](Introduction of # 2 nodejs)
  3. Try using the REPL [>>](Try using # 3 repl)
  4. Try running the file [>>](4 Try running the file)

1. Introduction of nvm

First, install nvm to manage the version of Node.js. Knowing the version of Node.js you are currently using You can switch to another version.

wsl


$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

When you're done

wsl


$ source ~/.bashrc 

Then, read the contents of .bashrc.

wsl


$ nvm

Node Version Manager

Note: <version> refers to any version-like string nvm understands. This includes:
  - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  - default (built-in) aliases: node, stable, unstable, iojs, system
  - custom aliases you define with `nvm alias foo`
The following is omitted. .. ..

If so, the installation is successful.

2. Introduction of Node.js

This time, I installed Node.js of Ver. 10.14.2.

wsl


$ nvm install v10.14.2
Downloading and installing node v10.14.2...
Downloading https://nodejs.org/dist/v10.14.2/node-v10.14.2-linux-x64.tar.xz...
###################################################################### 100.0%Computing checksum with sha256sum
Checksums matched!
Now using node v10.14.2 (npm v6.4.1)
Creating default alias: default -> v10.14.2
$ nvm use v10.14.2
Now using node v10.14.2 (npm v6.4.1)
$ node --version
v10.14.2

I have confirmed that the specified version of Node.js is installed.

3. Try using REPL

Think of it as a Node.js version of the console. (It feels like a Python console in Python) You can exit the REPL twice with Ctrl + c.

REPL


$ node
> 1+1
2
>
(To exit, press ^C again or type .exit)
> 

4. Try running the file

I think that the way to write the program should be the same as JavaScript. This time I will write a simple addition program and run it.

Source code

sum.js


'use strict';
function aAdd(num) {
    var res = 0;
    num[0] = 0;
    num[1] = 0;
    for (let s of num) {
        res += parseInt(s);
    }
    console.log(res);
}
aAdd(process.argv);

Execution result

wsl


$ node sum.js 1 2 3 4
10
$ node sum.js      
0

Rough commentary

This was a program that summed the arguments. The instructions are listed in process.argv. If you run $ node sum.js 1 1 1 2 3 The contents of the list are

[ '/home/yosse95ai/.nvm/versions/node/v10.14.2/bin/node',
  '/home/yosse95ai/sum.js',
  '1',
  '1',
  '1',
  '2',
  '3' ]

And so on.

So

num[0] = 0;
num[1] = 0;

Replace the non-numeric character string part (path part) with 0 in the part of. I think there is probably a more clever way.

in conclusion

This time, it was a fairly rudimentary commentary. I'm still a beginner, so I wrote it to organize my mind. It was probably a poor sentence, but thank you for your relationship. Goodbye: wave:

Related article

-Used from yarn introduction for Node.js in Linux environment

reference

-N Preparatory School 2020 Introduction to Programming

Recommended Posts

Used from the introduction of Node.js in WSL environment
Used from yarn introduction for Node.js in WSL environment
Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
[Introduction to Python] Thorough explanation of the character string type used in Python!
Fix the argument of the function used in map
From the introduction of pyethapp to the execution of contract
The story of building the fastest Linux environment in the world
Summary from the beginning to Chapter 1 of the introduction to design patterns learned in the Java language
Revit Dynamo Super Introduction Starting from the Basics-Basic Knowledge / Environment-
Examine the margin of error in the number of deaths from pneumonia
Check the operation of Python for .NET in each environment
Django + MongoDB development environment maintenance (in the middle of writing)
Commands often used in the development environment during Python implementation
What beginners learned from the basics of variables in python
Solve the problem of missing libcudart in Ubuntu 16.04 + CUDA 8.0 + Tensorflow environment
How to handle multiple versions of CUDA in the same environment
Django cannot be installed in the development environment of pipenv + pyenv
The story of participating in AtCoder
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
[Understanding in the figure] Management of Python virtual environment by Pipenv
Existence from the viewpoint of Python
Visualize the center of the rank battle environment from the Pokemon Home API
The story of the "hole" in the file
From Ubuntu 20.04 introduction to environment construction
The meaning of ".object" in Django
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
Verify the compression rate and time of PIXZ used in practice
Using TensorFlow in the cloud integrated development environment Cloud9 ~ Basics of usage ~
From the introduction of GoogleCloudPlatform Natural Language API to how to use it
Explanation and implementation of the XMPP protocol used in Slack, HipChat, and IRC
Predict the amount of electricity used in 2 days and publish it in CSV
Trends in programming languages from the perspective of GitHub (updated semi-annual changes)
pyenv + pyenv-Automatically load the virtualenv environment in the virtualenv environment
[Understanding in 3 minutes] The beginning of Linux
Check the behavior of destructor in Python
Summary of methods often used in pandas
The story of an error in PyOCR
General Theory of Relativity in Python: Introduction
Summary of frequently used commands in matplotlib
[Linux] List of Linux commands used in practice
Implement part of the process in C ++
Learning notes from the beginning of Python 1
About the virtual environment of python version 3.7
Omit BOM from the beginning of the string
Build the execution environment of Jupyter Lab
The result of installing python in Anaconda
Let's claim the possibility of pyenv-virtualenv in 2021
The basics of running NoxPlayer in Python
In search of the fastest FizzBuzz in Python
Introduction to docker Create ubuntu environment in ubuntu
I started Node.js in a virtual environment
Learning notes from the beginning of Python 2
Install the package in an offline environment
Introduction to Scapy ① (From installation to execution of Scapy)
Introduction of SoftLayer Command Line Interface environment
A collection of Numpy, Pandas Tips that are often used in the field
I want to use Python in the environment of pyenv + pipenv on Windows 10
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
Python scikit-learn A collection of predictive model tips often used in the field
Understand the images of various matrix operations used in Keras (Tensorflow) with examples
Algorithm Introduction Implement 4 types of sorting in Python from pseudo code of 3rd edition