Getting Started with Node.js WeChat Official Account Development

Setting up a server: WeChat Official Account development requires a server to receive and process messages. I recommend applying for a free cloud server from Tencent Cloud, click here to apply, available at 9:30 AM daily. I chose Ubuntu as the server image. For how to set up a Node environment on the server, refer to my other blog post Using Linux for Web Frontend Development. The principle of Official Account development is to set up a receiving interface; once developer mode is enabled, WeChat’s server will forward messages to this interface.

Read more

Node.js Morgan Module and Cluster Module

I’ve been tinkering with Node.js recently, following along with “Node.js in Action” to implement the Microblog project. Since the book was written in 2012, and Node has since been updated to v5.9.0 with Express also having undergone significant changes, much of the code in the book no longer works with current versions. For the implementation details, you can refer to this article: “Node.js Development Guide” Microblog Example with Express 4.x. BTW, the Express startup command has changed to npm start, which executes the www file in the bin directory, equivalent to running node ./bin/www directly. This post briefly covers the logging and multi-core CPU optimization topics mentioned in Chapter 6, along with an introduction to a debug tool. The complete Microblog code is available on GitHub: Click here

Read more

Node.js Development Guide - Book Notes

Chapter 3

  1. Single Loading:

    require does not load modules repeatedly. No matter how many times require is called, the module obtained is always the same one.

  2. Overriding exports:

    When encapsulating an object into a module, using exports.Hello = Hello requires require(‘./singleobject’).Hello to obtain the object. This can be simplified as follows: module.exports = Hello; Then you can directly obtain the object: var Hello = require(‘./hello’); hello = new Hello();

  3. Creating Global Links:

    npm link express; This allows you to use the globally installed express in the current directory.

  4. Use npm init to interactively initialize a standard package.json;
    Publish a package: npm publish;
    After modifying the version field in the json file, republish to update the version;
    Unpublish: npm unpublish;

Read more