npm init -y
mkdir src dist
npm i webpack -D
npm i webpack-cli -D
For multiple nodeJS version, use this management tool: nvm
NodeJS no need for a webserver.
REPL: Read-Eval-Print-Loop交互式解释器
process
: global modulefs
: non-global module
NodeJS中的IO是单线程,非阻塞的。
__dirname
: 当前js文件所在的目录
__filename
:表示当前正在执行的js文件的完整路径
error-first
: callback function, the first parameter is alway err object.
Use nodejs to create a webserver
-
Install
react react-dom
dependenciesnpm i -S react react-dom // Use these packages until production
react
: create components and virtual dom.react-dom
: dom manipulation and display, mainly usedReactDOM.render()
-
Use two important functions:
import React from 'react'; import ReactDOM from 'react-dom'; const myDiv = React.createElement('div', null, 'This is a div'); ReactDOM.render(myDiv, document.getElementById('app'));
-
To write
JSX
syntax statements, we need to installBabel
in our dev system.npm i -D babel-core babel-loader babel-plugin-transform-runtime npm i -D babel-preset-env babel-preset-stage-0 // Convert JSX syntax package npm i -D babel-preset-react