当前位置:网站首页>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.
边栏推荐
- The financing demand of 129 million yuan was released, and the roadshow of the Dake city project continued to irrigate the "good seedlings" of scientific innovation
- 主从复制及其原理
- How to use RPA to achieve automatic customer acquisition?
- 如何快速设计一套支持渲染富文本内容的跨端组件
- Experiment 2: Arduino's tricolor lamp experiment
- 开启TLS加密的Proftpd安全FTP服务器安装指南
- Responsive dream weaving template home decoration building materials website
- 响应式织梦模板户外露营类网站
- 当我看源码的时候,我在想什么?
- Meeting notice of meeting OA
猜你喜欢

密码安全如何保障?安全浏览器如何管理密码?

Day 14: continued day 13 label related knowledge

Interprocess communication - detailed explanation of the pipeline (explanation of graphic cases)

Explain the four asynchronous solutions of JS in detail: callback function, promise, generator, async/await
![[mqtt from introduction to improvement series | 09] Wireshark packet capturing and analyzing mqtt messages](/img/dd/c7ad9addb0d15611d996db87bf469f.png)
[mqtt from introduction to improvement series | 09] Wireshark packet capturing and analyzing mqtt messages

关于高并发,我想聊一聊。

网络安全漏洞管理的探索与实践

结合Retrofit 改造OKHttp 缓存

Responsive dream weaving template home decoration building materials website

如何利用 RPA 实现自动化获客?
随机推荐
外包公司“混”了2年,我只认真做了5件事,如今顺利拿到字节 Offer。
当Synchronized遇到这玩意儿,有个大坑,要注意
Responsive dream weaving template home decoration building materials website
Remember error scheduler once Asynceventqueue: dropping event from queue shared causes OOM
NPM install reports an error: eperm: operation not permitted, rename
FPGA刷题——存储器(RAM和FIFO的Verilog实现)
ES2022 的 8 个实用的新功能
How much is the report development cost in the application system?
应用系统中的报表开发成本值多少?
Talk about the implementation principle of feign
Jmeter之BeanShell生成MD5加密数据写入数据库
MQTT例程
where、having、group by、order by,is null,not in,子查询,delete,日期函数
3种过期策略
In depth analysis - Pretreatment
[quality] code quality evaluation standard
数据安全与隐私计算峰会-安全求交集在隐私计算中的发展和应用:学习
Polygon point test
聊聊接口性能优化的11个小技巧
[upload picture 2-cropable]