Installation configuration of NodeJS in Linux environment (HelloWorld)

  • 2020-05-17 07:35:01
  • OfStack

The simplest environment to install, test helloworld. For beginners!!

Install the script, please read carefully to execute line by line:


#!/bin/bash

# Check if it is installed 
rpm -qa | grep python

# Check the version 
python

# It is best to reinstall  Python Recommended version (  >= v2.5.0 & < 3.0.0  ), otherwise influence nodejs run 

# Go to the installation directory 
cd /usr/local/

# Delete the original installation 
rm -rf node
rm -rf node-v0.10.29-linux-x64

# Extract the compressed package 
tar -zxv -f node-v0.10.29-linux-x64.tar.gz

# Modify the directory 
mv node-v0.10.29-linux-x64 node

# Add environment variables and make them effective, as follows: 
export PATH=/usr/local/python/bin:/usr/local/node/bin:$PATH

# The test command 
node -v

#-------------------- test ----------------------------
# create nodejs Project directory 
mkdir -p /usr/local/nodejs/

# create hello.js file 
vi /usr/local/nodejs/hello.js

# It reads as follows: 
var http = require("http");
http.createServer(function(request, response) {
 response.writeHead(200, {
 "Content-Type" : "text/plain" //  The output type 
 });
 response.write("Hello World");//  Page output 
 response.end();
}).listen(8100); //  Monitor port number 
console.log("nodejs start listen 8102 port!");


# The background 
node /usr/local/nodejs/hello.js &

# Browser access 
http://192.168.2.2:8100/

When you visit the page, the word "Hello World" appears, indicating that the installation test was successful.


Related articles: