hexo has no method "init"

Created on 20 Feb 2016  ·  8Comments  ·  Source: hexojs/hexo

The objective is to run the hexo server using forever process management tool

// created app.js file at blog/app.js
require('hexo').init({command: 'server'});

// executed forever app.js from the directory
(function (exports, require, module, __filename, __dirname) { require('hexo').init({command: 'server'});
^
TypeError: require(...).init is not a function
at Object. (X:node\laurekamalandua.com\blogapp.js:1:79)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3

Most helpful comment

把app.js里的代码改成:

var Hexo = require('hexo');

hexo = new Hexo(process.cwd(), {});
hexo.init().then(function () {
hexo.call('server', {});
});

然后blog> forever app.js 即可!

All 8 comments

Admittedly we don't have enough documentation for Hexo module. PRs are welcome.

But we did cover the basics here: https://hexo.io/api/index.html

var Hexo = require('hexo');
var hexo = new Hexo(process.cwd(), options);
hexo.then((args) => hexo.call('server'));

Do check these code to learn how Hexo should be used.
https://github.com/hexojs/hexo-cli/blob/0.1.9/lib/index.js#L73-L77
https://github.com/hexojs/hexo/blob/master/test/scripts/hexo/hexo.js

Open new issue when you have problem integrating with forever.

me: opens issue to declare there are problems with forever integration
developer: closes ticket stating "open an issue when you have a problem integrating with forever"

@Xuanwo, need to do what? You're not being concise with your information.
Copy and past the reference in my app.js, change config files?

The support is really great on this one guys :+1: Perhaps I'll better shop around at other blogging frameworks, properly documented or where support can actually be met.

Do you aware that your issue is due to your misuse of API?

If someone can not clearly point out mistakes and provide a practical example or good explanation, then you should not expect the API to be used appropriately. The examples on https://hexo.io/api/ are not practical.

If you don't understand the error message and the difference between

var Hexo = require('hexo');
var hexo = new Hexo(process.cwd(), options);
hexo.then((args) => hexo.call('server'));

and

require('hexo').init({command: 'server'});

then you probably are not ready to code in JavaScript.

You are probably not ready to properly document your code. Because 6 replies further you still can't answer my question in regards to integration with forever. Case closed.

把app.js里的代码改成:

var Hexo = require('hexo');

hexo = new Hexo(process.cwd(), {});
hexo.init().then(function () {
hexo.call('server', {});
});

然后blog> forever app.js 即可!

Was this page helpful?
0 / 5 - 0 ratings