nodejs

65 篇文章 0 订阅
64 篇文章 0 订阅
Node

1.node.js是一个基于chrome v8引擎的javaScript运行环境
2.node.js是一个事件驱动非阻塞I/O模型,轻量高效
3.node.js的包管理器npm,是全球最大开源库生态系统
Node下载地址
安装后要在cmd使用,需要先配置环境变量,不用配到bin目录下,配到主目录即可

YPM

NPM: node Package Manger
包管理,分发工具,方便JavaScript开发中下载,安装,上传以及管理
包:模块
本地模块
全局模块

设置node环境配置:
cache : 下载缓存
prefix : 指定全局模块的存储位置(第三方下载模块的默认 存储地址)
npm config ls -l 查看配置

node_global:设置全局模块的文件夹
node_cache:缓存文件夹

    1. cache
      npm config set cache “路径”
      D:\Program Files\node-v10.16.0-win-x64\node_global\node_cache (临时缓存)
      npm config set prefix “路径” (会自动创建一个node_modules文件夹)
      D:\Program Files\node-v10.16.0-win-x64\node_global 全局模块的路径
    1. 该国内的厂库地址(ali)
      下载安装cnpm = npm (将厂库地址改为国内的)
      npm install cnpm -g --registry=https://registry.npm.taobao.org

         	我的电脑不知道为什么不可以安装cnpm,怎么都下载不下来,最后找到了其他解决方案
         	npm config set registry http://registry.npm.taobao.org/
         	将npm默认设置为淘宝镜像地址
         	当你想发布自己的包时,需要将地址修改回来
         	npm config set registry https://registry.npmjs.org/
      
    1. npm安装软件
      1. npm install 软件名称 -g/–save-dev
      2. npm install …
      3. npm install mysql -g

    现在全局查找是否存在指定模块
    如果要项目去全局模块中使用必须配置NODE_PATH环境变量
    D:\Program Files\node-v10.16.0-win-x64\node_global\node_modules
    node_path

用note访问数据库

let mysql = require('mysql')

let connection = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "root",
    database: "superzoo",
    port: "3306"

    
})

connection.query("select * from student",function(err,result){
    if(err){
        console.error(err);
        return;
        
    }
console.log("-----------start-----------");
console.log("-------------end------------");

result.forEach(item => {
    console.log(item.name)
});

})
connection.end();

可以对数据库进行任何操作

express

body-parser:用于处理json,text.请求参数
cookie-parser:获取cookie对象
multer:解决文件上传的表单问题

NPM 初始化项目包管理文件

package.json : 描述项目信息,包依赖信息

npm init -y : 安装默认配置生成 package.json文件
npm init

E:\node_project\webpack>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See npm help json for definitive documentation on these fields
and exactly what they do.

Use npm install <pkg> afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
包名,项目名称.默认安装当前文件夹名称生成
----package name: (webpack)
版本号
----version: (1.0.0)
项目描述
----description: this is npm init
程序入口
----entry point: (index.js)
测试模块
----test command:
git厂库地址
----git repository:
关键字
----keywords:
作者
----author: wuyu
开源协议
----license: (ISC)
通过上面配置,生成下面的代码是否保存

About to write to E:\node_project\webpack\package.json:
{
	  "name": "webpack",
	  "version": "1.0.0",
	  "description": "this is npm init",
	  "main": "index.js",
	  "scripts": {
	    "test": "echo \"Error: no test specified\" && exit 1"
	  },
	  "author": "wuyu",
	  "license": "ISC"
	}

输入yes将生成上面的文件
----Is this OK? (yes)

当需要为当前项目一次性下载所有模块
----npm install :会自动找当前项目下的package.json文件,读取包依赖进行下载

webpack
----程序入口: 默认webpage编译的时候会从src下面寻找js文件

----webpack.config.js : 配置文件
----package.json : 依赖包管理
----src : 编写源代码
----node_modules : node 本地模块文件
----dist : 编译后的文件位置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值