查看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. mybatis动态sql语句问题

    1.关于mybatis的insertintoselect命令未结束问题         添加:  useGeneratedKeys="false"     官网的解释是 允许 JD ...

  2. zabbix监控服务器部署

    1.服务器安装lamp环境 [root@monitor ~]# yum  install gcc gcc-c++ autoconf httpd php mysql mysql-server php-m ...

  3. ios 应用程序之间的跳转(内置程序的实现)

    ios 应用程序之间的跳转(内置程序的实现) 一个程序若要跳到另一个程序.需要在目标程序的plist文件里面修改: 打开info.plist,添加一项URL types 展开URLtypes,再展开I ...

  4. 搜索服务器xunsearch实现

    安装方法:   centos 6.6 64位   histroy:   12  cd /srv/   13  wget http://www.xunsearch.com/download/xunsea ...

  5. QT进度条QProgressBar的练习

    progressbar.h #ifndef PROGRESSBAR_H #define PROGRESSBAR_H #include <QProgressBar> class QStrin ...

  6. android process bar 几种style

    process bar 圆形style记录 1. style="?android:attr/progressBarStyleSmall" //根据主题变颜色 2. holo 主题下 ...

  7. Linux下最快速共享目录的方法

    Linux下最快速共享目录的方法 作者:chszs,未经博主允许不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 搭建FTP,或者是搭建网络文件系统,这 ...

  8. EOF 空格问题

    mysql -u $USER -p${PASSWORD} $DATABASE << EOF >/tmp/dd-$$ 2>/tmp/ddd-$$select *from $TAB ...

  9. [笔记]线性回归&梯度下降

    一.总述 线性回归算法属于监督学习的一种,主要用于模型为连续函数的数值预测. 过程总得来说就是初步建模后,通过训练集合确定模型参数,得到最终预测函数,此时输入自变量即可得到预测值. 二.基本过程 1. ...

  10. select option 下拉多选单选bootstrap插件使用总结

    <select id="example-getting-started" multiple="multiple"> <option value ...