Windows 10 Home Tera Term 4.105 (Terminal for Mac users)
・ Amazon Linux EC2 -SSH connection is possible -Outbound HTTP connection is possible
ec2-linux
$ cd ~
$ wget https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz
Get the latest version link from Official Site
node-v12.18.2-linux-x64.tar.xz
ec2-linux
$ cd ~
$ wget https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz
Make sure you have a tar file
ec2-linux
$ ls
$ node-v12.18.2-linux-x64.tar
Since the extension is xz, convert it to tar
ec2-linux
$ mv node-v12.18.2-linux-x64.tar.xz node-v12.18.2-linux-x64.tar
Defrost
ec2-linux
$ tar xvf node-v12.18.2-linux-x64.tar
Decompression is completed when various outputs are output and stopped
Set the path to node-v12.18.2-linux-x64 / bin where the execution command is installed and move
ec2-linux
$ export PATH=$PATH:~/node-v12.18.2-linux-x64/bin
$ cd node-v12.18.2-linux-x64/bin
Prepare a sample program called app.js
app.js
const http = require('http');
const hostname = 'localhost';
const port = 8080;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Run
ec2-linux
$ touch app.js
$ vim app.js
~~~~~~Paste the sample program(Please check the vim command yourself)~~~~~~
$ node app.js
Server running at http://localhost:8080/
Recommended Posts