macos安装python-nodejs_nodejs(1):mac 安装nodejs & electron 环境开发桌面应用

1,下载node安装包

Electron 是 Github 发布跨平台桌面应用开发工具,支持 Web 技术开发桌面应用开发,其本身是基于 C++ 开发的,GUI 核心来自于 Chrome,而 JavaScript 引擎使用 v8。

mac 安装node 6.10.3.pkg https://nodejs.org/

直接下一步,下一步安装即可。 This package will install Node.js v6.10.3 and npm v3.10.10 into /usr/local/.

然后 node 和 npm 命令就可以使用了。

创建第一个helloworld vi hello.js

var http = require('http');

http.createServer(function(req, res){

res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello World\n');

}).listen(8808, '127.0.0.1');

console.log('Server running at http://127.0.0.1:8808');

node hello.js

然后访问 http://127.0.0.1:8808/ 就可以看到效果了。

2,使用taobao 代理

nodejs的网站被屏蔽,可以使用淘宝的镜像。

修改 配置文件 ~/.bash_profile

#alias for cnpm

alias cnpm="npm --registry=https://registry.npm.taobao.org \

--cache=$HOME/.npm/.cache/cnpm \ --disturl=https://npm.taobao.org/dist \ --userconfig=$HOME/.cnpmrc

然后就可以使用 cnpm 命令了,(是china npm的意思吧)

以后都使用 cnpm 命令替换掉npm 命令。

3,下载helloworld 启动

官方已经提供了一个很简单的demo了。

# Clone this repository

git clone https://github.com/electron/electron-quick-start

# Go into the repository

cd electron-quick-start

# Install dependencies 注意是cnpm 命令!!

cnpm install

# Run the app

npm start

同时可以通过https://electron.atom.io/ 地址下载demo。也是集成了很多例子的。

4,获得视频

已经开启视频支持。不需要确认直接调用。

在浏览器上面还要用户确认下,这个直接调用了。

对于用户来说就是一个app应用。

// In the renderer process.

const {desktopCapturer} = require('electron')

desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {

if (error) throw error

for (let i = 0; i < sources.length; ++i) {

if (i == 0) {//获得第一个。api变了。名字叫别的了。

navigator.webkitGetUserMedia({

audio: false,

video: {

mandatory: {

chromeMediaSource: 'desktop',

chromeMediaSourceId: sources[i].id,

minWidth: 1280,

maxWidth: 1280,

minHeight: 720,

maxHeight: 720

}

}

}, handleStream, handleError)

return

}

}

})

function handleStream (stream) {

document.querySelector('video').src = URL.createObjectURL(stream)

}

function handleError (e) {

console.log(e)

}

5,总结

nodejs 类库,能做的事情还是很多的。功能非常强大。

之前认为这个只是一个前端同学学习的工具。

但后来认为,这个是一个新的框架体系。可以做的事情很多。

全栈工程师必须要学习的技术。使用好了,可以提高效率。

其实大多数的开发就是做应用开发的。

快速的将产品交付给用户使用就好了,然后回家睡觉。

真的不用纠结用啥技术。你应该不在乎,用户也不在乎。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值