link3014 link3015 link3016 link3017 link3018 link3019 link3020 link3021 link3022 link3023 link3024 link3025 link3026 link3027 link3028 link3029 link3030 link3031 link3032 link3033 link3034 link3035 link3036 link3037 link3038 link3039 link3040 link3041 link3042 link3043 link3044 link3045 link3046 link3047 link3048 link3049 link3050 link3051 link3052 link3053 link3054 link3055 link3056 link3057 link3058 link3059 link3060 link3061 link3062 link3063 link3064 link3065 link3066 link3067 link3068 link3069 link3070 link3071 link3072 link3073 link3074 link3075 link3076 link3077 link3078 link3079 link3080 link3081 link3082 link3083 link3084 link3085 link3086 link3087 link3088 link3089 link3090 link3091 link3092 link3093 link3094 link3095 link3096 link3097 link3098 link3099 link3100 link3101 link3102 link3103 link3104 link3105 link3106 link3107 link3108 link3109 link3110 link3111 link3112 link3113 link3114 link3115 link3116 link3117 link3118 link3119 link3120 link3121 link3122 link3123 link3124 link3125 link3126 link3127 link3128 link3129 link3130 link3131 link3132 link3133 link3134 link3135 link3136 link3137 link3138 link3139 link3140 link3141 link3142 link3143 link3144 link3145 link3146 link3147 link3148 link3149 link3150

VUE and Vuetify

Vuefity is Material Design Component Framework for Vue. Highlights:

  • Ready-Made Project Scaffolding: Vuetify comes ready to go with 8 pre-made vue-cli templates. From simple html to full-blown SSR you are ready to go in minutes.
  • Semantic Material Components: Be prepared for an armada of specialized components at your disposal. With over 80 in total, there is a solution for any application.
  • Vibrant Community: When you run into a roadblock, you need assistance right away. Vuetify offers chat support in our growing community on Discord.

Create a project using Vue and Vuetify

1
2
3
4
5
npm install @vue/cli -g
vue create my-app
cd my-app
vue add vuetify
npm run serve

Notes:

  1. the default web site will be http://localhost:8080
  2. Version: “vue”: “^2.5.17”, “vuetify”: “^1.3.0”

#1 Involve an Apple Style footer

  1. Open the ‘App.vue’
  2. Add these code bellow the <v-content> element and within v-app.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <v-content>
    <HelloWorld/>
    </v-content>

    <v-card height="100px" flat>
    <v-bottom-nav
    color="indigo"
    :value="true"
    fixed
    >
    <v-btn dark>
    <span>Video</span>
    <v-icon>ondemand_video</v-icon>
    </v-btn>

    <v-btn dark>
    <span>Music</span>
    <v-icon>music_note</v-icon>
    </v-btn>

    </v-bottom-nav>
    </v-card>
  3. open browser and test it.

Notes: for v-bottom-nav, use ‘fixed’ to make the footer always show at the bottom.

RabbitMQ 3.7.* Tips

RabbitMQ Management Plugin (Admin GUI)

The rabbitmq-management plugin provides an HTTP-based API for management and monitoring of RabbitMQ nodes and clusters, along with a browser-based UI and a command line tool.

It periodically collects and aggregates data about many aspects of the system. Those metrics are exposed to both operators in the UI and monitoring systems for long term storage, alerting, visualisation, chart analysis and so on.

The management plugin is included in the RabbitMQ distribution. Like any other plugin it must be enabled before it can be used. That’s done using rabbitmq-plugins: (Node restart is not required after plugin activation.)
Using ‘RabbitMQ Command Prompt (sbin dir)’ to run the following command:

1
rabbitmq-plugins enable rabbitmq_management

Write a node.js web crawler

How to write a node.js web crawler? And which node modules we will use? In this post, I’ll introduce how to write a web crawler using node.js

Node.js modules

cheerio

It is Fast, flexible & lean implementation of core jQuery designed specifically for the server. Using cheerio to work with html, and following links.

1
2
3
4
5
6
7
8
9
// cheerio
const cheerio = require('cheerio')
const $ = cheerio.load('<h2 class="title">Hello world</h2>')

$('h2.title').text('Hello there!')
$('h2').addClass('welcome')

$.html()
//=> <html><head></head><body><h2 class="title welcome">Hello there!</h2></body></html>

request

Request - Simplified HTTP client. Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.

1
2
3
4
5
6
const request = require('request');
request('https://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});

request-promise

The simplified HTTP request client ‘request’ with Promise support. Powered by Bluebird.
If you like the promise style, use this instead of the request directly.

1
2
3
4
5
6
7
8
var rp = require('request-promise');
rp('https://www.google.com')
.then(function (htmlString) {
// Process html…
})
.catch(function (err) {
// Crawling failed…
});

Full Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const rp = require('request-promise');
const cheerio = require('cheerio');
const options = {
uri: `https://www.google.com`,
transform: function (body) {
return cheerio.load(body);
}
};

rp(options)
.then(($) => {
console.log($);
})
.catch((err) => {
console.log(err);
});

Others

download image

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// using request
request(uri)
.pipe(fs.createWriteStream(fileName))

// demo using Q to download image and get a promise object.
function download(uri, fileName) {
return Q.nfcall(function (callback) {
request({
url: uri,
method: 'GET',
proxy: proxy
}, function (err, response, body) {
callback(err, body);
})
.pipe(fs.createWriteStream(fileName))
});
}

Top 10 Useful Service For Ubuntu Server.

Setup Basic Ubuntu Server

  • Make sure you select a LTS(Long Time Support) version of Ubuntu server
  • update installed services
    1
    apt-get update

Webmin

Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more. Webmin removes the need to manually edit Unix configuration files like /etc/passwd, and lets you manage a system from the console or remotely.

Install

Commands:

1
2
sudo apt-get update
sudo apt-get install webmin

For detail, following this guide to install webmin, http://www.webmin.com/deb.html.

Restart webmin

1
/etc/init.d/webmin restart

Shadowsocks

Install Shadowsocks Server

1
2
sudo apt update
sudo apt install shadowsocks-libev

configuration

By default it will auto start the service using this command

1
/usr/bin/ss-server -c /etc/shadowsocks-libev/config.json -u

The default of the config.json file is like this

1
2
3
4
5
6
7
8
{
"server":"127.0.0.1",
"server_port":8388,
"local_port":1080,
"password":"nacVulm2",
"timeout":60,
"method":"chacha20-ietf-poly1305"
}

You can change this configuration, and restart it.
e.g.

1
2
3
4
5
6
7
{
"server_port":443,
"password":"your_pwd_here",
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false
}

Install client

Please google to get the iOS/Android/Windows client for shadowsocks clients.

Top 10 Useful git commands

Merge code from master or other branch to current branch

1
2
3
git checkout your-current-branch
git pull origin master
git push

Force to restore to a server branch

1
git reset --hard origin/master

Create Tag

1
2
git tag "your_tag_name"
git push origin --tags

Copy changed files to other folder

e.g. copy to ‘d:\temp\’

1
git ls-files --modified | xargs -I {} cp --parents {} d:\temp\

Clean un-tracked files

  • To remove directories, run git clean -f -d or git clean -fd
  • To remove ignored files, run git clean -f -X or git clean -fX
  • To remove ignored and non-ignored files, run git clean -f -x or git clean -fx
  • Remove un-tracked/ignored folders and files, run git clean -fxd

Clean local git repository

to make the ‘.git’ folder a little smaller, you can clean the local git.

1
git gc --prune=now

CSS Tips

Change css style of the parent element

e.g. change the parent background color if it contains the child class

1
2
3
.parent .child{
background-color: white;
}

History of web Front-end build tools

WEB前端为什么需要构建工具

WEB技术的发展和局限

TODO
C# dll: metadata, “data about data”

AJAX(gmail) - node.js 飞速发展期

当学习了一种前端技术的时候,同时会有几种新的前端技术诞生。

还有,你选择的那种前端技术,也许已经过时了。

前端构建工具的需求

预处理

JS/CSS/HTML在设计之初并未料及它们会这样流行,整个Web已经形成一个大的分布式文档。 低层语言的更换或升级都因兼容性问题而面临着巨大困难。 这催生了各种中间语言个预处理器,例如SASS,LESS,CoffeeScript,Babel等。
这些预处理工具可以将我们的中间代码转换为可运行的JavaScript。 这些预处理器使得我们可以预先使用ECMA Script6,以结构化的方式编写CSS,或者在CommonJS环境中编写JavaScript等等。

风格与测试

在一个典型的工作流中,每次Push主分支或npm发布都应首先运行代码风格检查和单元测试。 我们需要这些操作能够在合适的时候自动执行。

资源压缩

在开发网站代码时,我们希望模块化地进行编码。每个业务逻辑,通用工具,或者架构元素都需要组织在单独的文件中。 但是如果用户浏览网页时也载入这么多源文件,那么页面打开速度会大打折扣。
因此在网站发布时需要将源码合并压缩, JavaScript可能还会需要模块化(AMD,CommonJS等), CSS文件可能也需要合并、添加兼容性前缀(-webkit-, -moz-)等。 这些重复性工作我们也希望写成脚本。

自动刷新

监听本地源代码变化,自动重新构建、刷新浏览器。

静态资源替换

最为复杂的构建需求是静态资源的URL替换。 因为生产环境中的资源地址可能和开发环境中很不一样, 可能是由于JS合并、CSS合并,也可能是由于应用了CDN加速。
我们需要在部署时更改所有HTML文件中的静态资源地址。

模块合并

在采用模块化的项目里会有很多个模块和文件,需要通过构建功能将模块分类合并成一个文件。

自动发布

更新代码后,自动构建出线上发布代码并传输给发布系统。

构建其实是工程化、自动化思想在前端开发中的体现,将一系列流程用代码去实现,让代码自动化地执行这一系列复杂的流程。构建为前端开发注入了更大的活力,解放了我们的生产力。

前端构建工具的发展

历史上先后出现了一系列构建工具,他们各有优缺点。由于前端工程师很熟悉 JavaScript,Node.js 又可以胜任所有构建需求,所以大多数构建工具都是用 Node.js 开发的。

Npm Scripts

在 Npm Scripts 和 Grunt 时代,Web 开发要做的事情变多,流程复杂,自动化思想被引入,用于简化流程;

Grunt

Gulp

在 Gulp 时代,开始出现一些新语言用于提高开发效率,流程处理思想的出现是为了简化文件转换的流程,例如将ES6转换为ES5;

语法太简洁了。感觉一句多余的代码都没有。或者说它只让你写必要的代码。用gulp官网的话说,这个叫做“代码优于配置”

构建项目的时间速度快。它充分利用了node流,优化(缩减)了很多对IO的操作。这样做的好处是你会发现gulp构建的时候每个Tast几乎都是ms级的,用了这个以后你会感觉grunt构建时候的速度原来那么慢。

FIS 3

Fis3是一个来自百度的优秀国产构建工具。相对于 Grunt、Gulp 这些只提供了基本功能的工具。Fis3集成了开发者常用的构建功能,如下所述。
读写文件:通过 fis.match 读文件,release 配置文件输出路径。
资源定位:解析文件之间的依赖关系和文件位置。
文件指纹:在通过 useHash 配置输出文件时为文件 URL加上 md5 戳,来优化浏览器的缓存。
文件编译:通过 parser 配置文件解析器做文件转换,例如将 ES6 编译成 ES5。
压缩资源:通过 optimizer 配置代码压缩方法。
图片合并:通过 spriter 配置合并 CSS 里导入的图片到一个文件中,来减少 HTTP 请求数。

Webpack

在Webpack时代,由于单页应用的流行,网页的功能和实现代码变的复杂、庞大,Web开发向模块化改进
(本地模块化工具)
Webpack 是一个打包模块化的JavaScript的工具,在Webpack里一切文件皆模块,通过 loader 转换文件,通过Plugin 注入钩子,最后输出由多个模块组合成的文件。Webpack 专注于构建模块化项目。

Rollup

Rollup 是一个和 Webpack 很类似但专注于ES6的模块打包工具。它的亮点在于,针对ES6源码进行 Tree Shaking,以去除那些已经被定义但没被使用的代码并进行 Scope Hoisting,以减少输出文件的大小和提升运行性能。然而 Rollup 的这些亮点随后就被 Webpack 模仿和实现了。由于 Rollup 的使用方法和 Webpakc 差不多,所以这里就不详细介绍如何使用 Rollup 了,而是详细说明他们的差别:
Rollup 是在Webpack 流行后出现的替代品;
Rollup 生态链不完善,体验还不如Webpack;
Rollup 的功能不如 Webpack 完善,但其配置和使用更简单;
Rollup 不支持 Code Spliting, 但好处是在打包出来的代码中没有 Webpack 那段模块的加载、执行和缓存的代码。
Rollup 在用于打包JavaScript库时比 Webpack 更有优势,因为其打包出来的代码更小、更快。但他的功能不够完善,在很多场景下都找不到现成的解决方案。

Overview

  • 在 Npm Scripts 和 Grunt 时代,Web 开发要做的事情变多,流程复杂,自动化思想被引入,用于简化流程;
  • 在 Gulp 时代,开始出现一些新语言用于提高开发效率,流程处理思想的出现是为了简化文件转换的流程,例如将ES6转换为ES5;
  • 在Webpack时代,由于单页应用的流行,网页的功能和实现代码变的复杂、庞大,Web开发向模块化改进。

Web 前端项目的演进

从简单到复杂
从多页到单页
前后端的分离
前端模块化/组件化/工程化

具体的演进过程如下

多页

后端直接输出 Web 内容, 没有异步请求后端接口数据

多页 + Ajax + 拼字符串输出 HTML

静态页面变成”动态”页面, 需要调用后端接口获取数据, 在前端渲染出页面的内容

多页 + Ajax + 前端模版引擎(artTemplate)

拼字符串难以维护, 引入前端模版引擎来实现数据层与展现层的分离
多页 + Ajax + 前端 MVVM 框架(Vue)
引入前端 MVVM 框架来取代前端模版引擎, 数据与视图同步更新, 更彻底的分离出展现层

多页 + Ajax + 前端 MVVM 框架(Vue) + (模块化)依赖管理(RequireJS)

前端的依赖混乱难以管理一直是前端的毒瘤, 项目变大后团队的协作是个问题, 很容易就发生 JS(全局) 和 CSS(全局) 的冲突
JS 和 CSS 本身在语言层次上没有提供模块化解决方案
JS 一般通过闭包导出命名空间到全局来规避冲突, 实现简易的模块化
CSS 一般通过命名规范来规避冲突, 例如 BEM 命名规范
如果只是简单的项目, 可以引入历史技术 AMD 来实现模块化和依赖管理
一旦有了模块化管理, 势必会慢慢涉及到前端构建方案(Grunt/Gulp), 来做前端的打包和发布

单页 + Ajax + 前端 MVVM 框架(Vue) + (模块化)依赖管理(webpack/ES2015) + 前端路由(vue-router)

单页的复杂度是前端的一个转折点, 你会遇到越来越多前端工程化方面的问题, 首先需要了解的就是前端路由的实现原理(hashchange/HistoryAPI)
因为实现单页的基础就是引入前端路由来模拟出”多个页面视图”的逻辑切换
模块化之后, 为了模块的重用, 一般会定义出公共模块和各个页面视图模块, 模块的数量会越来越多, 首次需要加载的文件也就会越来越多, 你肯定不想浏览器首次加载的时候需要发送几十个请求吧, 因此我们需要前端构建工具来打包我们的模块
然而你肯定也不想所有的模块都打包成一个文件(all in one), 这样肯定会拖慢页面首屏加载的速度, 因此迫切的需要代码分隔和模块懒加载(一般是根据路由的懒加载)
那么既然已经引入了前端工程化构建的过程, 那么前端一些最新的规范(例如 ES2015), 我们也就可以用起来了, 让我们面向未来编程

单页 + Ajax + 前端 MVVM 框架(Vue) + (模块化)依赖管理(webpack/ES2015) + 前端路由(vue-router) + 状态管理(Redux)

页面视图上需要控制的状态越来越多, 多个页面视图的状态又有依赖, 到底是哪里触发了某个状态的改变, 哪个视图又会受到这个状态改变的影响?
你是不是通过全局事件做过组件之间的通信? 你能够预测到状态与视图之间的对应关系吗? 是不是越发地难以控制难以调试了?
引入前端状态管理的架构方案让代码结构标准化可控
view = f(state)

前端模块化/组件化/工程化

将前端项目当成一项系统工程进行分析、组织和构建从而达到项目结构清晰、分工明确、团队配合默契、开发效率提高的目.

模块化和组件化一个最直接的好处就是复用,同时我们也应该有一个理念,模块化和组件化除了复用之外还有就是分治,我们能够在不影响其他代码的情况下按需修改某一独立的模块或是组件,因此很多地方我们及时没有很强烈的复用需要也可以根据分治需求进行模块化或组件化开发。

Apple VPP (Volume Purchase Program)

VPP means “Volume Purchase Program”. The Volume Purchase Program allows businesses and educational institutions to purchase your apps in volume and distribute them within their organizations. Contract developers can also offer customized apps to customers who have a Volume Purchase Program for Business account.

It is said ‘Whether you have ten employees or ten thousand, the Volume Purchase Program makes it simple to find, buy, and distribute apps and books to meet your every business need’. It just a way to help our customer distribute our App. Customers need to register an account from Apple to use it first. Then “Using an MDM solution, assign apps directly to your devices or invite users to participate if distributing via Apple ID.”

Develop Custom Apps for Business

It allow you to engage with business customers to design and build customized apps that work best for them. Custom B2B apps are delivered privately through the Volume Purchase Program. You can distribute to authorized buyers that you identify, giving your business customers privacy and security.

Customize Apps

Meet the unique needs of businesses by privately offering custom B2B apps to Volume Purchase Program for Business members.

  • Tailored look and feel, such as company logo or branding
  • Specific functionality for a business process or workflow
  • Special configuration for IT environments
  • Security features for sensitive or private company data
  • Custom features for partners, dealers, or franchises

Distribute Privately

Custom apps are distributed privately to authorized Volume Purchase Program for Business members that you identify in iTunes Connect. Customers sign in and purchase their apps on the Volume Purchase Program store.

Submit as B2B apps

Setup and develop is the same as normal apple store ones. Only the submit is a little different. Select the custom B2B distribution option in iTunes Connect. If your app contains sensitive data, provide sample data and authentication for our review team.

What Business Customers Need to Do

  • Enroll: Once your customer has a volume purchasing account with Apple, they can easily buy apps that meet their business needs, and get custom B2B apps you’ve built for them.
  • Purchase: Custom B2B apps will appear in your customer’s Volume Purchase Program account. Customers select the app and enter the quantity they want to purchase on the Volume Purchase Program store
  • DistributeYour business customers can use third-party Mobile Device Management (MDM) solutions to help manage and distribute their apps. Or they can provide redemption codes to their users via email or an internal website.

Node.js Interview Questions and Answers


More Readings

Basic Questions

In JavaScript, which types are pass by reference? And which types are pass by value? How to pass a variable by reference?

Simply speaking, objects are pass by reference. Basic types are pass by value. We can pass basic types by reference using boxing technique.

Pass by reference and pass by value is a basic question. It is fundamental part to understand how does JavaScript’s memory work. It is hardly to have further discussion without understanding reference.

In coding session, we use questions like how to write a json object copy function to assess candidate.

Sometimes, we ask about the difference between == and ===. And then, true or false of [1] == [1]. Without a good foundation, candidate may make a wrong conclusion because of the wrong understanding of == and ===.

More on pure javascript: Javascript Interview Questions and Answers

How to judge whether a interface is asynchronous? Is it asynchronous while a callback provided?

This is a open question, you can have your own way to judge.

Simply use the callback function is not asynchronous, IO operation may be asynchronous, in addition to the use of setTimeout and other ways are asynchronous.

How to implement a Sleep function?

1
2
3
4
5
function sleep(sleepMs) {
var start = Date.now(), expire = start + sleepMs;
while (Date.now() < expire) ;
return;
}

Node.js Modules

What is V8 module

We are not talking about V8, but V8 module in Node.js. It’s used for opening built-in events and interfaces of V8 engine in Node.js. Because these interfaces are defined by underlying part of V8, so we can’t say it’s absolutely stable.

Is the Eventemitter.emit synchronous or asynchronous?

Synchronous.

Events module is a very important core module in Node.js. There are many important core APIs in the node that depend on Events , for example, Stream is implemented based on Events, and fs, net, ‘http’ are implemented based on ‘Stream’, ‘Events’ is so important to Node.js.

The EventListener calls all listeners synchronously in the order in which they were registered. This is important to ensure the proper sequencing of events and to avoid race conditions or logic errors.
And when you destroy this class, don’t forget to destroy these emitters too , because inside the class, some listener may cause memory leak.

if a website has a interface A, and in some cases, interface A can be the endless loop, unfortunately, if you triggered this endless loop, what will be the impact on your website?

If endless loop logic trigger in your website, the whole process will be blocked, and all request will timeout, asynchronous code will never be executed, and your website will be crashed.

In Node.js environment javascript code has only one single thread. Only the current code has been executed, the process will cut into the event loop, and then pop out the next callback function from the event queue to start the implementation of the code, as long as an infinite loop can block the execution of the entire js process

How to implement an async.reduce

You need to know that reduce is analyze a recursive data structure and through use of a given combining operation, recombine the results of recursively processing its constituent parts, building up a return value.

What’re the difference between child_process.fork and fork in POSIX?

In Node.js, child_process.fork() calls POSIX fork(2). You need manually manage the release of resources in the child process for fork POSIX. You don’t need to care about this problem when using child_process.fork, beacuse Node.js will automatic release, and provide options whether the child process can survive after the parent process is destroyed.

Does the death of parent process or child process affect each other? What is an orphan process?

The death of a child process will not affect the parent process. When the child process dies (the last thread of the thread group, usually when the “lead” thread dies), it will send a death signal to its parent process. On the other hand, when the parent process dies, by default, the child process will follow the death. But at this time, if the child process is in the operational state, dead state, etc., it will be adopted by process identifier 1(the init system process) and become an orphaned process. In addition, when the child process dies(“terminated” state), the parent process does not call wait() or waitpid() to return the child’s information in time, there is a PCB remaining in the process table. The child process is called a zombie process.

IPC(Inter-process communication), Before IPC channel was set up, how the parent process and the child process communicate between each other? If there is no communication, how is IPC set up?

When you create a child process via child_process, you can specify the env (environment variable) of the child process. When starting the child process in Node.js, the main process sets up the IPC channel first, then pass the fd(file descriptor) of the IPC channel to the child process via environment variable (NODE_CHANNEL_FD). Then the child process connects to the parent process via fd.

Finally, for the issue of inter-process communication (IPC), we generally do not directly ask the IPC implementation, but will ask under what conditions you need IPC, and the use of IPC to deal with any business scene.

What is Daemon Process

Daemon Process is a very basic concept of the server side. Many people may only know that we can start a process as a daemon by using tools such as pm2, but not what is a process and why using it. For excellent guys, daemon process implement should be known.

The normal process will be directly shut down after the user exits the terminal. The Process starting with & and running in the background will be shut down when the session (session group) is released. The daemon process is not dependent on the terminal(tty) process and will not be shut down because of the user exiting the terminal.

What is Buffer

Buffer is the class to handle binary data in Node.js, IO-related operations (network / file, etc.) are all based on Buffer. An instance of the Buffer class is very similar to an array of integers, but its size is fixed, And its original memory space is allocated outside the V8 stack. After the instance of the Buffer class is created, the memory size occupied by it can no longer be adjusted.

New Buffer () interface was deprecated from Node.js v6.x, The reason is that different types of parameters will return different types of Buffer objects, So when the developer does not correctly verify the parameters or does not correctly initialize the contents of the Buffer object, it will inadvertently introduce security and reliability problems to the code.

What is String Decoder

String Decoder is a module to decode buffers to strings, as a supplement to Buffer.toString, it supports multi-byte UTF-8 and UTF-16 characters. Such as:

1
2
3
4
5
6
7
8
const StringDecoder = require('string_decoder').StringDecoder;
const decoder = new StringDecoder('utf8');

const cent = Buffer.from([0xC2, 0xA2]);
console.log(decoder.write(cent)); // ¢

const euro = Buffer.from([0xE2, 0x82, 0xAC]);
console.log(decoder.write(euro)); // €

What’s the current working directory of the process? What’s it for?

You can obtain the current working directory by using process.cwd(). It usually is the directory when the command line starts. It can also be specified at startup. File operations, etc. obtain the file by using the relative path which is relative to the current working directory.

Some of the third-party modules that can obtain the configuration look for the configuration file through your current directory. So if running the start script in the wrong directory, you will get wrong rusults. You can change working directory by using process.chdir() in your code.

How should I handle unexpected errors? Should I use try/catch, domains, or something else?

Here are the error handling methods in Node.js:

  • callback(err, data) Callback agreement
  • throw / try / catch
  • Error event of EventEmitter

What is uncaughtException

he uncaughtException event of process object will be triggered when the exception is not caught and bubbling to the Event Loop. By default, Node.js will ouput the stack trace information to the stderr and end process for such exceptions, And adding listener to uncaughtException event can override the default behavior, thus not end the process directly.

1
2
3
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});

Should we use Domain for error handling?

No.
In the early Node.js, try/catch is unable to capture asynchronous errors, And the error first callback is just an agreement, without mandatory and very cumbersome to write. So in order to catch the exception very well, Node.js introduces domain module in v0.8.

But domain also brought more new problems. Such as dependent modules can not inherit the domain you defined, Causing it can’t cover errors in dependent modules. Furthermore, Many people (especially new bie) didn’t understand memory / asynchronous processes and other issues in Node.js, they didn’t do well when using domain to process errors and let the code continue, this is likely to cause the project to be completely unserviceable (Any problems are possible, And all kinds of shit…)

And now, it is ‘deprecate’.

Vue or Angular in 2018

You should first make a clear decision as to whether you need a single-page-application (SPA) or if you’d rather take a multi-page approach.

Angular

Angular is a TypeScript-based Javascript framework. Developed and maintained by Google, it’s described as a “Superheroic JavaScript MVW Framework”. Angular (also “Angular 2+”, “Angular 2” or “ng2”) is the rewritten, mostly incompatible successor to AngularJS (also “Angular.js” or “AngularJS 1.x”). While AngularJS (the old one) was initially released in October 2010, it is still getting bug-fixes, etc. — the new Angular (sans JS) was introduced in September 2016 as version 2.

Vue

The greatest benefit of Vue is it’s absence of pedigree. It is fresh and has little baggage. It has been learning from the mistakes and successes of React & Angular. The way we see it, Vue is lightweight & easy to learn.
It has got some fairly basic docs but they do a good job, and while there isn’t a great deal to learn compared to angular — this is a good thing as it’s deceptively powerful. PageKit, Python China are two of of the projects using Vue among many. Here’s the list. Also, it has two way data binding facility like Angular and Virtual DOM like React.

Compare

Long-term support & migrations

Regarding Angular, there is a blog post about versioning and releasing Angular starting with the v2 release. There will be one major update every six months, and there will be a deprecation period of at least six months (two major releases). There are some experimental APIs marked in the documentation with shorter deprecation periods. There is no official announcement yet, but according to this article, the Angular team has announced long-term-support versions starting with Angular 4. Those will be supported for at least one year beyond the next major version release. This means Angular 4 will be supported until at least September 2018 with bug-fixes and important patches. In most cases, updating Angular from v2 to v4 is as easy as updating the Angular dependencies. Angular also offers a guide with information as to whether further changes are needed.

The update process for Vue 1.x to 2.0 should be easy for a small app — the developer team has asserted that 90% of the APIs stayed the same. There is a nice upgrade-diagnostic migration-helper tool working on the console. One developer noted that the update from v1 to v2 was still no fun in a big app. Unfortunately, there is no clear (public) roadmap about the next major version or information on plans for LTS versions.

One more thing: Angular is a full framework and offers a lot of things bundled together. React is more flexible than Angular, and you will probably wind up using more independent, unsettled, fast-moving libraries — this means that you need to take care of the corresponding updates and migrations on your own. It could also be a detriment if certain packages are no longer maintained or some other package becomes the de facto standard at some point.