当前位置:网站首页>Quickly master nodejs installation and getting started
Quickly master nodejs installation and getting started
2022-07-29 02:32:00 【Mighty CRUD】
One 、Nodejs
1.1、Nodejs Introduce
Official website :http://nodejs.cn/
Node It is a let. JavaScript Development platform running on the server , It makes JavaScript Become and PHP、Python、Perl、Ruby Wait for the server-side language to be equal to the script language . Published on 2009 year 5 month , from Ryan Dahl Development , The essence is right. Chrome V8 The engine is packaged .
To put it simply Node.js It's running on the server side JavaScript. Node.js It's based on Chrome JavaScript A platform built at runtime . The underlying architecture is :javascript. file extension :.js
Node.js It's an event driven I/O Server side JavaScript Environmental Science , be based on Google Of V8 engine ,V8 The engine performs Javascript Very fast , Very good performance .
Download the corresponding to your system Node.js edition :
Download address :https://nodejs.org/zh-cn/download
Help document :https://nodejs.org/zh-cn/docs
About Nodejs:https://nodejs.org/zh-cn/about
1.2、 install
Open... After downloading The next step of mindless installation The default installation is enough
After the installation is completed, check whether the installation is successful :
node -v
1.3、 Summary
Nodejs It's a computer language , Running in the system v8(jvm) In the engine . The file suffix is js The command to run is :node
Two 、Nodejs Quick start
2.1、 Quick start -Hello World
1、 Create folder nodejs
2、 establish helloworld.js
Be similar to java Medium System.out.println("")
console.log('Hello World!!!')
function :node helloworld.js
result :hello world!!!
3、 Open command line terminal :Ctrl + Shift + y
The browser kernel consists of two parts :
DOM Rendering engine ;
- java script Parser (js engine )
- js Running in the browser kernel js Inside the engine
4、 Summary
Node.js It runs out of the browser environment JavaScript Program , be based on V8 engine
2.2、Node - Implement request response
1、 establish httpserver.js ;
// The import module is require Is similar to the import java.io
const http = require('http');
// 1: Create a httpserver service
http.createServer(function(request,response){
// How do browsers know hello server!!!
response.writeHead(200,{
'Content-type':'text/plain'}); // The meaning of this sentence is : Tell the browser that it will
// With text-plain Parse hello server This data .
// Output content to the browser
response.end("<strong>hello server!!!</strong>");
}).listen(8888);
console.log(" The service you started is :http://localhpst:8888 To start successfully !!");
// 2: Monitor one port 8888
// 3: Start the running service node httpserver.js
// 4: Access in browser http://localhost:8888
2、 Run the server program ;
node httpserver.js
3、 After the server starts successfully , Enter... In the browser :http://localhost:8888/ see webserver Running successfully , And the output html page
4、 Out of Service :ctrl + c
2.3、Node- operation MYSQL database
Reference resources :https://www.npmjs.com/package/mysql
1: install mysql rely on
npm install mysql
2: Definition db.js To operate
//1: Import mysql Dependency package , mysql A module belonging to a third party is similar to java.sql The same thing
var mysql = require("mysql");
// 1: Create a mysql Of Connection object
// 2: Configure data connection information
var connection =mysql.createConnection({
host:"127.0.0.1",
port:3306,
user:"root",
password:"mkxiaoer",
database:"testdb"
});
// 3: Open up connections
connection.connect();
// 4: perform curd
connection.query("select * from user",function(error,results,fields){
// If the query fails , Direct selling
if(error)throw error;
// The query is successful
console.log("results = ",results);
});
// 5: Close the connection
connection.end();
// The last step : function node db.js See the effect
3: New database :db_test And table kss_user surface
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 60011
Source Host : localhost:3306
Source Schema : testdb
Target Server Type : MySQL
Target Server Version : 60011
File Encoding : 65001
Date: 20/01/2021 21:38:55
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of kss_user
-- ----------------------------
INSERT INTO `user` VALUES (1, ' Zhang San ');
INSERT INTO `user` VALUES (2, ' Li Si ');
SET FOREIGN_KEY_CHECKS = 1;
4、 function db.js
node db
If you want to develop more complex software based on Node.js The application background , Need to learn more Node.js Of Web Develop related frameworks express,art-template、koa etc.
边栏推荐
猜你喜欢
npm install 报错 Error: EPERM: operation not permitted, rename
DevOps 团队如何抵御 API 攻击?
Prometheus + AlertManager 消息预警
Practice and experience of security compliance in instant messaging scenarios
结合Retrofit 改造OKHttp 缓存
裂开了,一次连接池参数导致的雪崩问题
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)
Chapter 3 business function development (deletion and modification of clue remarks)
如何在多御安全浏览器中自定义新标签页?
On Multithreading
随机推荐
Never pass a request to an asynchronous thread. There is a hole
进程间通信---对管道的详细讲解(图文案例讲解)
npm install 报错 Error: EPERM: operation not permitted, rename
应用系统中的报表开发成本值多少?
Kbxxxxx is not necessarily a patch, but also a description of a solution to a problem
Hexadecimal to string
Kubesphere multi node installation
响应式织梦模板家装装饰类网站
工程经济学名词解释
基于对象的实时空间音频渲染丨Dev for Dev 专栏
外包公司“混”了2年,我只认真做了5件事,如今顺利拿到字节 Offer。
Waiting queue wait_ queue
密码安全如何保障?安全浏览器如何管理密码?
Explain asynchronous tasks in detail: task status and lifecycle management
Rust 列表(Vec)复制
Eight practical new functions of es2022
Time pit in MySQL driver
The first of the five tips for using browsers efficiently is the most practical
6年测试经验,教大家测试~如何把控项目
When I look at the source code, what am I thinking?