restore snapshot shell snapshot.sh
!#/bin/bash wget https://nodejs.org/dist/v12.13.1/node-v12.13.1-linux-x64.tar.xz tar xvf node-v12.13.1-linux-x64.tar.xz export PATH=/home/ubuntu/node-v12.13.1-linux-x64/bin:$PATH wget https://manning-content.s3.amazonaws.com/download/0/ddbbd36-251d-42ef-9934-55e5a881a336/FinalSourceCode.zip sudo apt update sudo apt install unzip unzip FinalSourceCode.zip mv Final\ Source\ Code/ sls sudo apt install python-pip pip install awscli which aws_completer cp ~/.bashrc ~/.bashrc_orig tee -a ~/.bashrc <<-'EOF' complete -C '/home/ubuntu/.local/bin/aws_completer' aws export PATH=/home/ubuntu/node-v12.13.1-linux-x64/bin:$PATH EOF aws configure npm install claudia -g claudia -v 5.11.0 cd chapter-03 npm install claudia create \ --region ap-northeast-1 \ --api-module api packaging files npm install -q --no-audit --production npm WARN pizza-api@1.
Debugging the Build Process Gatsby’s build and develop steps run as a Node.js application
which you can debug using standard tools for Node.js applications.
Debugging with Node.js’ built-in console console.log(args) VS Code Debugger (Auto-Config) Preferences: Type node debug into the search bar. Make sure the Auto Attach option is set to on.
launch.json
launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes.
bind eip gatsby develop -- --host=0.0.0.0 Prettier VS Code plugin JSX The hybrid “HTML-in-JS” is actually a syntax extension
of JavaScript, for React, called JSX
In pure JavaScript, it looks more like this:
src/pages/index.js
import React from "react" export default () => React.createElement("div", null, "Hello world!") Now you can spot the use of the ‘react’ import! But wait. You’re writing JSX, not pure HTML and
JavaScript. How does the browser read that?
如果xml文件带有名字空间,XPATH支持
还不够完善。下面介绍两种可以工作的方式
namespace for XML documents http.get("https://wubigo.com/en/sitemap.xml", function(res) { useNamespaces const select = xpath.useNamespaces({"ns0": "http://www.sitemaps.org/schemas/sitemap/0.9"}); const nodes = select("//ns0:loc", doc); nodes.forEach((value) => console.log("ns0:"+value)); Implementing a Default Namespace Resolver const nsResolver = function nsResolver(prefix) { const ns = { 'ns0' : 'http://www.sitemaps.org/schemas/sitemap/0.9', 'mathml': 'http://www.w3.org/1998/Math/MathML' }; return ns[prefix] || null; }; nsResolver.lookupNamespaceURI = nsResolver; var result = xpath.evaluate( "//ns0:loc", // xpathExpression doc, // contextNode nsResolver, // namespaceResolver xpath.XPathResult.ANY_TYPE, // resultType null // result ) node = result.
与回调函数的区别 不用写错误条件if (err) return callback(err) Promise能被作为对象返回并被后期调用
回调
function successCallback(result) { console.log("Audio file ready at URL: " + result); } function failureCallback(error) { console.error("Error generating audio file: " + error); } createAudioFileAsync(audioSettings, successCallback, failureCallback); promise
const promise = createAudioFileAsync(audioSettings); promise.then(successCallback, failureCallback); or
createAudioFileAsync(audioSettings).then(successCallback, failureCallback); 状态 Promise有三种状态
pending: Initial Case where promise instantiated. fulfilled: Success Case which means promise resolved. rejected: Failure Case which means promise rejected.
对象创建有如下几种方式
使用{} let animal = {} animal.name = 'Leo' animal.energy = 10 animal.eat = function (amount) { console.log(`${this.name} is eating.`) this.energy += amount } animal.sleep = function (length) { console.log(`${this.name} is sleeping.`) this.energy += length } animal.play = function (length) { console.log(`${this.name} is playing.`) this.energy -= length } 构造函数 function Animal (name, energy) { let animal = {} animal.name = name animal.energy = energy animal.eat = function (amount) { console.
set registry npm config set registry=http://registry.npm.taobao.org npm config ls -l userconfig = "C:\\Users\\Administrator\\.npmrc" declare variables ES6 comes with two more options to declare your variables: const and let. In JavaScript ES6, you will
rarely find var anymore.
A variable declared with const cannot be re-assigned or re-declared. It cannot get mutated (changed,
modified)
Immutability is embraced in React and its ecosystem. That’s why const should be your default