Installation and testing of Mac node js environment

Installation and testing of Mac node js environment

1. Configuration of mac node.js environment

Step 1: Open the terminal and enter the following command to install Homebrew

/usr/bin/ruby -e "$(curl -fsSL"

Homebrew official website

Step 2: Install node, enter the following command in the terminal

brew install node

Step 3: Check whether the node installation is successful

2. New test program

Step 1: Create a new file test.js

var http = require('http');

var data = {key : 'value', hello: 'world'};

var srv = http.createServer(function (req, res) {
	res.writeHead(200, {'Content-Type': 'application/json'});

srv.listen(8080, function() {
	console.log('listening on localhost:8080');

Step 2: Use the terminal to find the file directory where it is located and run

 node Desktop/test.js listen on localhost:8080

Step 3: Visit through the browser and return the data in json format

Step 4: The front end can analyze data through this interface.

Thank you very much: Li Yugang's blog (installation and testing of node.js environment on mac)