npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fakelearnnodejs

v0.0.1

Published

The note of learn nodejs

Downloads

1

Readme

LearnNodeJS

知识点

全局对象与全局变量

全局对象指的是global,它的属性叫全局变量

下面介绍一些常用的全局变量:

  1. process 它用于描述当前Node.js进程状态的对象,提供了一个与操作系统的简单接口.
    • process.argv 是命令行参数数组,,第一个元素是node,第二个元素是脚本文件名,从第三个元素开始每个元素是一个运行参数。
    // argv.js
    console.log(process.argv);
    
    > node argv.js 1991 name=fake

$ node process.js 1991 name=fake [ 'c:\Program Files\nodejs\node.exe', 'd:\www\learnNodeJS\process.js', '1991', 'name=fake' ] ```

- process.stdout是标准输出流,通常我们用console.log()向标准输出打印字符,而process.stdout.write()函数提供了更底层的接口.

- process.stdin 是标准输入流,初始时它是被暂停的,要想从标准输入读取数据,你必须恢复流,并手动编写流的事件响应函数。
```
process.stdin.resume();
process.stdin.on('data', function(data) {
    process.stdout.write('read from console: ' + data.toString());
});
```
- process.nextTick(callback)的功能是为事件循环设置一项任务,Node.js 会在下次事件循环调响应时调用 callback。

因为node.js是单线程,如果在一个回调函数中出现大量的计算,会导致一个事件循环中的其他事件响应缓慢,所以把复杂的计算拆分成多个步骤在下一个tick执行能有效地提高响应速度。
不要使用setTimeout(fn,0)代替process.nextTick(callback),前者比后者效率要低得多。
``` javascript
function sleep(d) {
    var t = Date.now();
    while (Date.now() - t <= d) {}
}

function complexCaculation1() {
    console.log("complex thing. 1")
    sleep(1000);
}

function complexCaculation2() {
    console.log("complex thing. 2")
    sleep(1000);
}

function doSomethingInOneStep() {
    console.log('do complex thing.');
    complexCaculation1();
    complexCaculation2();
}

function doSomethingInSeveralStep() {
    console.log('do complex thing.');
    complexCaculation1();
    process.nextTick(complexCaculation2);
}
```

- process.platform 可以通过这个参数写跨平台程序

Skills

  1. supervisor

    supervisor会监视你对代码的改动,并自动重启 Node.js。使用方法很简单:

    > npm install -g supervisor
    > supervisor app.js
  2. 包发布

    > npm init #生成规范化的package.json
    > npm adduser #登陆账号
    > npm publish #发布到npmjs.org
    > npm unpublish #从线上删除
  3. 调试工具

    调试方法有命令行下的debug, eclipse IDE, node-inspector. cmd下的debug太原始,不好用,eclipse要安装IDE不爽,node-inspector可以利用浏览器来调试,符合前端开发的习惯。

    > npm install -g node-inspector  #安装node-inspector
    > node-inspector #运行
    > node --debug-brk=5858 debug.js #运行调试程序

    在浏览器中打开http://127.0.0.1:8080/debug?port=5858

Thanks to NodeJS.