Install node.js and npm on Mac

If you change your Mac, you need to install noed.js and npm to record it
. First visit the official website of node.js (https://nodejs.org/en/download/)

After clicking the download, click install all the way to complete the installation

Then open - terminal - enter node -v to return the currently installed version number to see the picture

Then enter npm -v to get

that the installation is normal, 
then open the user directory in Finder (that is, the Mac administrator, click on the sidebar to open the directory, create a Js file, name it helloworld.js, and enter in the js file these contents )

const http = require('http');

 

const hostname = '127.0.0.1';

const port = 1337;

 

http.createServer((req, res) => {

res.writeHead(200, { 'Content-Type': 'text/plain' });

res.end('Hello World\n');

}).listen(port, hostname, () => {

console.log(`Server running at http://${hostname}:${port}/`);

});

After the save is successful, open the terminal

Enter  node helloworld.js to get

Then copy the following IP address to the browser and open it

 

This configuration is successful

If opportunity doesn’t knock, build a door.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326425931&siteId=291194637