Node JS World

Node JS World

Environment

tested on Ubuntu

Install nvm/node/npm/yarn

  • nvm : node version manager
  • node: node js
  • npm: node package manager
# goto the nvm office website and find the latest version, e.g. 0.34.0

# install nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

# list remote versions
nvm ls-remote

# install the latest on
nvm install v11.8.0

# use the version
nvm use v11.8.0

# always default to the latest available node version on a shell
nvm alias default node
  • yarn: a faster node package manager
# configure repository
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

# install yarn
sudo apt-get update && sudo apt-get install yarn

Yarn

# add a package global
yarn global add create-react-app

# add a package local and save to dependencies
yarn add prismjs

# add a package local and save to devDependencies
yarn add gulp --dev

# add a package local and save to peerDependencies
yarn add prismjs --peer

# add a package local and save to optionalDependencies
yarn add prismjs --optional

React

  • installation
# install create-react-app
yard global add create-react-app

# create a react application
npx create-react-app my-app

Development

dependencies vs devDependencies vs peerDependencies vs bundleDependencies

  • npm install will get:

    • dependencies: installed
    • devDependencies: installed
    • bundelDependencies: indirectly installed via the packed way
    • peerDependencies: a warning message
  • npm install --production will get:
    • dependencies: installed
    • bundelDependencies: indirectly installed via the packed way
    • peerDependencies: a warning message

npm pack will pack bundelDependencies

when to use devDependencies

  • you do not want the package will be installed on the production environment, e.g. testing/utility packages.

when to use bundelDependencies

  • you modified a dependency, so you do not want to use the one from npm registry
  • you own projects

when to use peerDependencies

  • you know there would be multiple incompatible versions, and need customers to solve the dependency manually.

Development Tools

  • npx: node package runner
  • babel: a JavaScript compiler.
    put in next-gen JavaScript -> Get browser-compatible JavaScript out
  • gulp: a task management
    office website

    • install and start
## Install the gulp command line utility
npm install gulp-cli -g

## Install the gulp package in your devDependencies
## cd <project folder>
npm install gulp --save-dev

## Verify your gulp versions
gulp --help

## new a gulp task file
touch gulpfile.js

ESLint

The pluggable linting utility for JavaScript and JSX

  • install and start
# install the eslint package in your devDependencies
yarn add eslint --dev
yarn add eslint-config-react-app --dev
yarn add eslint-plugin-import --dev
yarn add eslint-plugin-flowtype --dev
yarn add eslint-plugin-jsx-a11y --dev
yarn add eslint-plugin-react --dev
yarn add flow-bin --dev

## check version
npm run lint -v
## or ./node_modules/eslint/bin/eslint.js -v
yarn flaw version
  • configure eslint
    new a project root file: .eslintrc
{
  "extends": [
    "react-app",
    "eslint:recommended",
    "plugin:react/recommended"
  ],
  "plugins": [
    "react"
  ],
  "settings": {
    "react": {
      "createClass": "createReactClass",
      "pragma": "React",
      "version": "detect",
      "flowVersion": "0.53"
    },
    "propWrapperFunctions": [
      "forbidExtraProps",
      {
        "property": "freeze",
        "object": "Object"
      },
      {
        "property": "myFavoriteWrapper"
      }
    ],
    "linkComponents": [
      "Hyperlink",
      {
        "name": "Link",
        "linkAttribute": "to"
      }
    ]
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "rules": {
    "no-console": "off"
  }
}
  • disable a rule for a line
// eslint-disable-next-line no-console
  • disable a rule for a file
/* eslint-disable no-console */
  • disable a rule for the project via package.json
    "rules": {
      "no-console": "off"
    }
  • configure flow
# crete .flowconfig
yarn flaw init

edit .flowconfig

[ignore]
.*/node_modules/config-chain/.*

[include]

[libs]

[lints]
all=warn

[options]

[strict]
nonstrict-import
unclear-type
untyped-import
untyped-type-import
unsafe-getters-setters
sketchy-null
  • check rules
yarn lint
yarn flaw
  • To fix formatting errors, run the following:
yarn lint -- --fix

husky

Git hooks made easy - Husky can prevent bad git commit, git push and more ?? woof!

  • install
npm install husky --save-dev
  • configure
// package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "npm test",
      "pre-push": "npm test",
      "...": "..."
    }
  }
}

原文地址:https://www.cnblogs.com/steven-yang/p/10340196.html

时间: 2024-11-06 12:39:31

Node JS World的相关文章

node.js的安装及配置

一.安装 直接在浏览器搜索node.js,在官网上下载(一般旧版的更加稳定,比如下载4.4.7版本) 点击DOWNLOADS 往下翻,点击Previous Release Windows下载msi(64位/32位) 根据提示一步步安装,安装之后的文件夹如下: 在cmd命令行下输入node -v,如果出现如下,说明安装成功: 二.关于配置 在安装路径下新建两个文件夹: 创建完两个空文件夹之后,打开cmd命令窗口,输入 npm config set prefix "D:\Program Files

Node.js: Extend and Maintain Applications + large scale

https://blog.risingstack.com/node-js-mysql-example-handling-hundred-gigabytes-of-data/ My secondary goal with this article is to help you decide if Node.js + MySQL is a good fit for your needs, and to provide help with implementing such a solution. h

1.node.js windows环境搭建

作为服务端运行javascript的平台的NodeJs,把前台javascript移到了服务器端,Google V8引擎使其运行效率非常高,它可以异步,无任何阻塞运行程序.nodejs包含http服务器,可以为我们实现 web系统设计,客户端javascript编译器,等一系列的功能. 工具/原料 windows系统电脑 ,电脑可以上网 方法/步骤 下载windows平台nodejs环境安装包,百度一下nodejs官网,找到DOWNLOADS点击,找到Windows Installer 如果为6

在Node.js中使用RabbitMQ系列二 任务队列

在上一篇文章在Node.js中使用RabbitMQ系列一 Hello world我有使用一个任务队列,不过当时的场景是将消息发送给一个消费者,本篇文章我将讨论有多个消费者的场景. 其实,任务队列最核心解决的问题是避免立即处理那些耗时的任务,也就是避免请求-响应的这种同步模式.取而代之的是我们通过调度算法,让这些耗时的任务之后再执行,也就是采用异步的模式.我们需要将一条消息封装成一个任务,并且将它添加到任务队列里面.后台会运行多个工作进程(worker process),通过调度算法,将队列里的任

node.js搭建代理服务器请求数据

1.引入node.js中的模块 1 var http = require("http"); 2 var url = require("url"); 3 var qs = require("querystring"); 2.创建服务器 //用node中的http创建服务器 并传入两个形参 http.createServer(function(req , res) { //设置请求头 允许所有域名访问 解决跨域 res.setHeader("

Node.JS 文件读写,把Sheet图集转换为龙骨动画图集

Node.JS 文件读写,把Sheet图集数据转换为龙骨动画图集数据 var fs = require("fs") var readline = require("readline"); var rl = readline.createInterface({ input:process.stdin, output:process.stdout }); var path = undefined; var dbName = undefined; rl.question(

10个常见的Node.js面试题

如果你希望找一份有关Node.js的工作,但又不知道从哪里入手评测自己对Node.js的掌握程度. 本文就为你罗列了10个常见的Node.js面试题,分别考察了Node.js编程相关的几个主要方面. 在进入正文之前,需要提前声明两点: 这些问题只是Node.js知识体系的一个局部,并不能完全考察被面试者的实际开发能力. 对现实世界开发中遇到的问题,需要的是随机应变与团队合作,所以你可以尝试结对编程. Node.js面试题列表 什么是错误优先的回调函数? 如何避免回调地狱? 如何用Node来监听8

CentOS6.5 安装Node.js

Node.js的安装通常有两种方式:自己编译源代码和使用编译好的文件,我这里使用编译好的文件目前我的home目录下有刚下载来的node-v4.2.3-linux-x641.首先解压缩 tar xvf node-v4.2.3-linux-x64 2.设置链接 ln -s /home/node-v4.2.3-linux-x64/bin/node /usr/local/bin/node ln -s /home/node-v4.2.3-linux-x64/bin/npm /usr/local/bin/n

使用NPM安装Node.js模块以及调试

npm npm 作为Node.js的包管理器,是经常用到的工具. 注意:全局安装一个框架,需要加参数-g npm install -g express 安装后 在项目中只需要导入包即可 var http = require('http'); 调试 调试Node的最简单的方式就是console.log(),但是有时候也需要单步调试 在需要调试的地方写入debugger node debug *.js node中的测试命令: next,n:单步执行 cont,c:继续执行,直到遇到下一个断点 ste

用Node.js开发Windows 10物联网应用

(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 未来10年内,物联网将会如移动互联网这样深入到我们生活的各方各面.所以微软现在对物联网进行了大量的投资,比如Windows 10就有一个单独的IoT版本.而今天推荐的文章是告诉大家如何把Node.js开发带到Windows 10 IoT中. 在月初Build大会上,微软发布了Windows 10 IoT Core Insider Preview,这个版本可以安装到树莓派2(Raspberry Pi