How to configure and express Node.js

How to configure and express Node.js

This section describes how to configure the node with the express

Configuration Node.js

1, the installation package download Node.js Node.js Download

Here Insert Picture Description

2, in accordance with the process step by step installation package go

Here Insert Picture Description
Continue to click Next to OK

Here Insert Picture Description

3, the terminal can be seen inside the version installed Node

Enter the following statement:
Here Insert Picture Description

4, create an application using Node.js

(1) Use http.createServer () method to create server and bind port 8888 using the listen method.
Create a server.js

var http = require('http');

http.createServer(function (request, response) {

    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // 发送响应数据 "Hello World"
    response.end('Hello World\n');
}).listen(8888);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');

(2) to use in the terminal node server.js
Here Insert Picture Description
(3) Next, open the browser to access http://127.0.0.1:8888/, that says you will see a "Hello World" page

Here Insert Picture Description



Configuration express

Using the common command to install npm Node.js Web frame modules express

$ npm install express
Released four original articles · won praise 5 · Views 108

Guess you like

Origin blog.csdn.net/weixin_43205774/article/details/105126393