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

Node JS World的更多相关文章

  1. node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理

    一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...

  2. 利用Node.js的Net模块实现一个命令行多人聊天室

    1.net模块基本API 要使用Node.js的net模块实现一个命令行聊天室,就必须先了解NET模块的API使用.NET模块API分为两大类:Server和Socket类.工厂方法. Server类 ...

  3. Node.js:进程、子进程与cluster多核处理模块

    1.process对象 process对象就是处理与进程相关信息的全局对象,不需要require引用,且是EventEmitter的实例. 获取进程信息 process对象提供了很多的API来获取当前 ...

  4. Node.js:理解stream

    Stream在node.js中是一个抽象的接口,基于EventEmitter,也是一种Buffer的高级封装,用来处理流数据.流模块便是提供各种API让我们可以很简单的使用Stream. 流分为四种类 ...

  5. Node.js:Buffer浅谈

    Javascript在客户端对于unicode编码的数据操作支持非常友好,但是对二进制数据的处理就不尽人意.Node.js为了能够处理二进制数据或非unicode编码的数据,便设计了Buffer类,该 ...

  6. node.js学习(二)--Node.js控制台(REPL)&&Node.js的基础和语法

    1.1.2 Node.js控制台(REPL) Node.js也有自己的虚拟的运行环境:REPL. 我们可以使用它来执行任何的Node.js或者javascript代码.还可以引入模块和使用文件系统. ...

  7. Node.js npm 详解

    一.npm简介 安装npm请阅读我之前的文章Hello Node中npm安装那一部分,不过只介绍了linux平台,如果是其它平台,有前辈写了更加详细的介绍. npm的全称:Node Package M ...

  8. Node.js入门(一)

    一.Node.js本质上是js的运行环境. 二.可以解析js代码(没有浏览器安全级的限制): 提供系统级的API:1.文件的读写 2.进程的管理 3.网络通信 三.可以关注的四个网站: 1.https ...

  9. Node.js学习笔记——Node.js开发Web后台服务

    一.简介 Node.js 是一个基于Google Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又高效.Node.j ...

  10. Node.js入门

    开始之前,安利一本正在看的书<站在两个世界的边缘>,作者程浩,上帝丢给他太多理想,却忘了给他完成理想的时间.OK,有兴趣的可以看一看. node.js如标题一样,我也是刚开始接触,大家一起 ...

随机推荐

  1. 【跨域】#001 JSONP原理解析【总结】

    一.JSONP 是什么? 1.1 概念 JSONP(JSON with Padding)是资料格式 JSON 的一种“使用模式”,可以让网页从别的网域要资料.由于同源策略,一般来说位于 server1 ...

  2. 【原创】由于python的导入方式引起的深坑

    目录结构: test/ sacc/ __init__.py app.py logger.py /views __init__.py main.py 事情是这样的,logger里面是一个类LoggerF ...

  3. Hadoop HA on Yarn——集群配置

    集群搭建 因为服务器数量有限,这里服务器开启的进程有点多: 机器名 安装软件 运行进程 hadoop001 Hadoop,Zookeeper NameNode, DFSZKFailoverContro ...

  4. SGU---101 无向图的欧拉回路

    题目链接: https://cn.vjudge.net/problem/SGU-101 题目大意: 给定你n张骨牌,每张牌左右两端有一个数字,每张牌的左右两端数字可以颠倒,找出一种摆放骨牌的顺序,使得 ...

  5. javascript中对数组对象的深度拷贝

    在前端开发的某些逻辑中,经常需要对现有的js对象创建副本,避免污染原始数据的情况. 如果是简单的一维数组对象,可以使用两个原生方法: 1.splice var arr1 = ['a', 'b', 'c ...

  6. 2339: [HNOI2011]卡农

    Description 首先去除顺序不同算一种的麻烦,就是最后答案除以总片段数\(2^m-1\) 设\(f_i\)表示安排\(i\)个片段的合法种类 那么对于任何一个包含\(i-1\)个片段的序列(除 ...

  7. Java并发编程--5.信号量和障碍器

    Semaphore信号量 简介 它本质上是一个共享锁,限制访问公共资源的线程数目,它也被称为计数信号量acquire()许可一个线程, Semaphore – 1; 没有可用的许可时,Semaphor ...

  8. ZOJ 4103 浙江省第16届大学生程序设计竞赛 D题 Traveler 构造

    这个题,正赛的时候也没有过,不过其实已经有了正确的解法,可惜时间不多了,就没有去尝试. 题意是有n个点,i点能通向i-1,然后i和i*2.i*2+1互通. 请你构造一种路径从1能走完所有点,并且不重复 ...

  9. Java泛型学习一

    Java泛型 所谓泛型,就是变量类型的参数化.泛型是java1.5中引入的一个重要特征,通过引入泛型,可以使编译时类型安全,运行时更少抛出ClassCastException的可能.一提到参数化,最熟 ...

  10. 错误检查roswtf

    准备 在你开始本教程之前请确保roscore没在运行. 安装检查 roswtf 可以检查你的ROS系统并尝试发现问题,我们来试看: $ roscd $ roswtf 你应该会看到(各种详细的输出信息) ...