Connect Hexo with Express.js and develop fast, simple and flexible websites
- Make sure that you have Node.js v8 or above installed.
- Clone this repo using
git clone https://github.com/phen0menon/hexo-with-express.git
- Move to the appropriate directory:
cd hexo-with-express/blog
. - Run
npm install
in order to install dependencies. - Run
hexo generate
in order to generate Hexo's public files. - Move to the root directory of the project:
cd ../
- Run
npm install
in order to install project-root dependencies.
At this point you can run npm run start
to see the example app at http://localhost:4000
When you edit your blog and want to see some changes, use hexo generate
in order to create public HTML files and see them on your Express.js server.
Important: Don't forget to restart the server.
You will need to add other modules to this project, depending on your purposes. For example, you may want to add node-postgres to communicate with PostgreSQL database.
Please read the following section before installing any dependencies
This project uses a two package.json project structure. This means, you will have two package.json
files.
./package.json
in the root of your project./blog/package.json
insideblog
folder
- If the module connects with Hexo platform, it should be listed under
dependencies
in./blog/package.json
- Modules used for developing (like node-postgres) should be included in
dependencies
in./package.json
- Modules used for building, testing and debugging should be included in
devDependencies
in./package.json
If you want to change url route of blog, for example, you want to change route like this: http://domain.com/blog
Please read the following section before doing anything.
- Go to
hexo-with-express/blog
and open_config.yml
file. Find URL section and change the following:
url: http://localhost:4000/your_blog_dir
root: /your_blog_dir
- In this folder run
hexo generate
. - Go to
hexo-with-express/
and openindex.js
. Change the following:
app.use('/your_blog_dir', express.static('blog/public'));
- Restart the server to apply the changes.
- Open
http://localhost:4000/your_blog_dir
.
This project bootstrapped with: Hexo, Express.js
Made with ❤️ for Hexo