查看Node 基本配置
$ npm config ls -l

$npm help install
将展开install的help文档

初始化目录 npm init 根据提示完成 将生成package.json

全局安装和本地安装
globally —- This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin {prefix} is usually something like /usr/local
locally —- This installs your package in the current working directory. Node modules go in ./node_modules, executables go in ./node_modules/.bin/,

npm install grunt # 本地安装
npm install -g grunt-cli # 全局安装
全局安装将安装到 /usr/local/lib/node_modules中
对于win则是 %APPDATA%\npm\node_modules PS要注意的是 win的路径和linux是相反的

PS设置Node的代理(在公司中很重要哦)
set HTTP_PROXY=http://proxy.xxxx.com:8080
之后再运行
 
 
npm install --save grunt
--save 参数,这个参数的作用,就是会在你安装依赖的同时,自动把这些依赖写入 package.json。命令执行完成之后,查看 package.json,会发现多了一个 dependencies 字段

PS 安装前要确保目录拥有权限 注意要加上sudo
sudo chmond -R 777 yourPath/

使用淘宝镜像
$ npm install xxx --registry=http://registry.npm.taobao.org
$ npm install xxx --save --registry=http://registry.npm.taobao.org
其中xxx是你想要安装的包

或者这样可以一直使用淘宝镜像  方案来自http://segmentfault.com/a/1190000000471219
npm install -g cnpm --registry=https://registry.npm.taobao.org
PS  --save 和 --save-dev区别
devDependencies are for the development-related scripts, e.g. unit testing, packaging scripts, documentation generation, etc.
dependencies are required for production use, and assumed required for dev as well.

安装好后 当前目录下会出现一个 node_modules 文件夹 里面就有你安装的express 等包
你的app.js 应该是放在和 node_modules同级目录下 而不是 express内(express中也有一个node_modules)

关于require的用法
var foo1 = require('./foo');
var foo2 = require('./foo.js'); //这两种都是引入文件 ./是不能省去的 否则和引入模块混淆
var foo3 = require('foo'); //这个是引入node_modules中的模块

exports 和 module.exports
exports.module = xxx; 给当前模块增加一个xxx属性
module.exports = xxx; 将xxx作为模块返回

require路径 http://nqdeng.github.io/7-days-nodejs/
总之require会先从/home/user/这样的全局目录中加载依赖 然后再是node_modules 下面找

debug  node-inspector

$ npm install -g node-inspector  --registry=http://registry.npm.taobao.org
$ node --debug app.js  //debug模式启动
之后会打开http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 这个页面 就可以debug了
自动更新node-dev 
npm install -g node-dev  --registry=http://registry.npm.taobao.org

然后原来运行node app.js 改为 node-dev --debug app.js 运行就可以,这样修改文件后就会自动更新了.

OR  nodemon也是相同的功能  还是用nodemon吧  star更多呢
 
 
 
 
远程调试
远程调试和普通调试一样  node可能是线上的服务器  不运行在本地
参考 http://blog.techbeta.me/2015/10/nodejs-debug/
在node的机器上安装node-inspector  
然后打开两个terminal都登陆到服务器  
node --debug app.js  (默认是5858这个port)
使用7000端口
node --debug=7000 app.js  
 
 
另一个则是

node-inspector --web-port=8082  (8082是监听端口)

之后会提示

Visit http://127.0.0.1:8082/?port=5858 to start debugging.

那么就访问 http://xxxxx:8082/?port=5858  就可以debug远程的node了   xxxxx就是你的主机名

使用了7000端口则是http://xxxxx:8082/?port=7000

 

NodeJS 从0开始的更多相关文章

  1. CentOS 上安装 nodejs v11.0.0

    下载 nodejs 淘宝 nodejs 镜像地址:https://npm.taobao.org/mirrors/node wget 命令下载: wget https://npm.taobao.org/ ...

  2. centos 上安装nodejs v8.0.0

    新建目录www 下载nodejs wget https://npm.taobao.org/mirrors/node/v8.0.0/node-v8.0.0-linux-x64.tar.xz 解压 tar ...

  3. window 10 64bit 安装nodejs v7.0.5 + npm v4.1.2 + Express 4.x及搭建web开发环境

    1.先安装nodejs.npm. 2.然后安装Express (4.0之后需要安装express-generator) npm install -g express npm install -g ex ...

  4. nodejs+express4.0+mongodb安装方法 for Linux, Mac

    废话不多说 1:下载nodejs包 下载地址例如以下:http://www.nodejs.org/download/ 下载source code版本号须要解压后到其文件夹运行./configure,然 ...

  5. nodeJs 5.0.0 安装配置与nodeJs入门例子学习

    新手学习笔记,高手请自动略过 安装可以先看这篇:http://blog.csdn.net/bushizhuanjia/article/details/7915017 1.首先到官网去下载exe,或者m ...

  6. NodeJS - Express4.0错误:Cannot read property 'Store' of undefined

    Express在使用mongodb的时候app配置出错 //settings.js module.exports={ cookieSecret:"xxxx", db:"d ...

  7. Nodejs 8.0 踩坑经验汇总

    .Linq:Linq to sql 类 高度集成化的数据库访问技术 使用Linq是应该注意的问题: 1.创建Linq连接后生成的dbml文件不要变动,生成的表不要碰,拖动表也会造成数据库连接发生变动, ...

  8. 【安装Nodejs】CentOS7 下安装NodeJs+Express+MongoDB+Redis

    最近想拿NodeJS做个文档管理系统玩玩,看看mongdb的gridfs效率咋样,谁晓得因为一个Yeoman的脚手架,整来整去的把文件权限全部搞乱,一想算了,还是重来搞一套吧! 1.安装  yum i ...

  9. 从零开始,做一个NodeJS博客(一):Heroku上的最简NodeJS服务器

    标签:NodeJS,Heroku 0 这里是这个伪系列的第一篇,因为我也不知道自己能不能做完,然后到底能做成什么样子.总之,尽力而为吧,加油. 1 Heroku App 的构成 Heroku 所谓的 ...

随机推荐

  1. 【codevs】2292图灵机游戏

    题 Shadow最近知道了图灵机是什么(Shadow:就是一行格子和一个机器头移来移去的呗!),于是他突发奇想,创造了一个新游戏——“图灵机游戏”(Shadow:好听吧?). 游戏规则如下: 在一条长 ...

  2. leetcode Linked List Cycle python

    # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...

  3. JVM学习之常用概念

    方法区     当JVM使用类装载器装载某个类时,它首先要定位对应的class文件,然后读入这个class文件,最后,JVM提取该文件的内容信息,并将这些信息存储到方法区,最后返回一个class实例. ...

  4. mysql--自动增长

    create table teacher( t_id int primary key auto_increment, #auto_increment 自动增长 需要整型,还需要索引 t_name va ...

  5. this的用法this.name=name 这个什么意思

    public Employee(string name, string alias){ // Use this to qualify the fields, name and alias: this. ...

  6. xtrabackup执行备份要拥有的权限

    xtrabackup备份的原理: xtrabackup直接复制datadir目录中的文件到备份目录下.这样问题就来了,在备份的时候mysql可以还在执行写入操作:所以xtrabackup会不停的去扫描 ...

  7. SQL Server 固定角色

    1. 查看固定服务器角色 execute sp_helpsrvrole; 管理: execute master..sp_addsrvrolemember @logingName='neeky' @ro ...

  8. Java程序员快速入门Go语言

    这篇文章帮助Java程序员快速入门Go语言. 转载至 开源中国社区. http://www.oschina.net 本文将以一个有代表性的例子为开始,以此让Java程序员对Go语言有个初步认识,随后将 ...

  9. libvirt C-API

    1,warming-up Specifying URIs to libVirt;name parameter to virConnectOpen or          virConnectOpenR ...

  10. 04737_C++程序设计_第8章_多态性和虚函数

    例8.1 分析下面程序的输出结果. 例8.2 分别使用指针和引用的display函数. #include <iostream> using namespace std; const dou ...