picture


what is nodejs?

nodejs is an open source and cross-platform JavaScript runtime environment. How to understand this sentence? If we need to raise fish, then we need water and pool, fish is like JavaScript, water and pool are node.js

Eh, JavaScript doesn't run on the browser? Yes, nodejs is based on Google Chrome's kernel V8 engine. Based on this powerful core heart and excellent performance, he has become a front-end developer who can also write server-side code.

Supplement: Most front-end developers write browser-side, client-oriented code, so the client-side is mainly used, and the server-side is mainly to provide interface API calls. Therefore, with the emergence of nodejs, front-end developers can also write server-side code. code, and deploy to nodejs for other services to call.




how to install?

Official packages for all major platforms are available at  http://nodejs.cn/download/ .

Other package managers for MacOS, Linux and Windows are listed at  http://nodejs.cn/download/package-manager/ 


设置环境变量NODE_PATH = C:\\my_work\\nodejs\\node_modules
深入研究 Node.js 之前,我建议您能很好地掌握主要的 JavaScript 概念

First Node.js program: Hello World!

1.下载 node.js, 解压后运行文件夹内的 node.exe
2.运行 : node -v 是否正确运行
2.创建js文件
3.输入内容 console.log("Hello World");
4.运行命令: node 对应目录下的js文件


Node.js creates your first application

1.引入 required 模块    var http = require("http");
2.创建服务器 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/>');
3.使用 node 命令执行 node server.js Server running at <http://127.0.0.1:8888/>


Thank you for your support and attention, more welcome to read the original text