[DOCKER] Hello world in node.js


Use Node.js to display hello world on the console


Use Visual Studio Code (hereinafter VSCode) Use Node.js container with Docker

What is Node.js

--A mechanism that allows javascript, which is originally a client-side language, to be used on the server side (* 1) ――You can create various things such as websites, web applications, smartphone sites, games, etc. => Paypal, uver, etc. are also made with Node.js! ――We are good at processing a large amount of data, and the processing speed is fast.

Download Node.js to Docker

Install Docker, a VScode extension, in advance. (* 2)

Create docker-compose.yml file

Create a Nodejs-sample-app (any folder name is fine) folder. Create a docker-compose.yml file under it. This is a standard file when downloading a container to docker, so the file name is fixed. A yml file is a text file written according to the YAML format, and is used for data transfer. This time, it is described as follows.


version: "3"
        image: node:14.15
            - .:/project
        tty: true
        working_dir: /project
        command: bash

Meaning of each item

Download the image to doceker

Using the terminal function of VSCode, enter the Nodejs-sample-app folder and type the following command to download Node.js to docker.

docker-compose up -d

image スクリーンショット_2021-01-16_10_53_46.jpg

I opened docker and it looks like this! Screenshot_2021-01-16_10_54_20.jpg

Select Attach shell to enter the container (see photo) スクリーンショット_2021-01-16_12_33_56.jpg

You can switch between the local terminal and the container terminal here スクリーンショット_2021-01-16_12_38_45.jpg

Creating an app.js file

Create a app.js file in the same hierarchy as docker-compose.yml. This time it is described as follows


console.log("Hello nodejs");

At the terminal inside the container

$ node app.js

 When you type the command and the following is displayed, Node.js environment construction is complete!


Recommended Posts

Hello world in node.js
"Hello World" in Java
Hello World in Java
Spring Boot Hello World in Eclipse
Hello World in java in eclipse now
hello, world in Vanilla Java-EHW2018 "MVP"
Hello world in Java and Gradle
Read "Hello world"
Java, Hello, world!
Java Hello World
Hello, World! In the bootstrap loader area
[Practice! ] Display Hello World in Spring Boot
"Hello, World!" With Kotlin + CLI in 5 minutes
Hello World with JavaFX 11 (OpenJFX) in Liberica JDK 11
Java Learning (1)-Hello World
Read System.out.println ("hello, world")
Let's write Hello World
Studying Java-Part 1-Hello World
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Hello World on WebAssembly
Hello World with Micronaut
Hello World with Spring Boot
Java history in this world
Hello World with Spring Boot!
Hello World with VS Code!
java hello world, compile, run
Hello World with Spring Boot
Java beginners read Hello World
Hello World with SpringBoot / Gradle
Hello, World! With Asakusa Framework!
Hello World for ImageJ Java Plugin
Until "Hello World" with Spring Boot
Hello World on AWS Lambda + Java
Hello world with Kotlin and JavaFX
Hello World with Docker and C
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
(Intellij) Hello World with Spring Boot
Hello World with GlassFish 5.1 + Servlet + JSP
Create PDF with itext7 ~ Hello World ~
"Hello world" for ImageJ with Eclipse
Hello World with GWT 2.8.2 and Maven
Android OS (7.1.2) build and Hello World
Programming for the first time in my life Java 1st Hello World
"Teacher, I want to implement a login function in Spring" ① Hello World
Creating an Elasticsearch Plugin Series (1) Hello World
Hello World with Eclipse + Spring Boot + Maven
Hello world with Java template engine Thymeleaf
Java development with Codenvy: Hello World! Run
Hello World on Mac VS Code Java
Introduction to Ratpack (3) --hello world detailed explanation
Hello world with Kotlin and Tornado FX
How Spring Security works with Hello World
(IntelliJ + gradle) Hello World with Spring Boot
Minimal Java environment construction and Hello World