× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Hexo framework: Creating blogs with Node.js

In this article we are going to meet Hexo, a lightweight and powerful blog framework based on Node.js.

Motivation

Hexo is a free and open source framework to create blogs with Node.js. With a lightweight and fast engine, it allows us to quickly write new posts and deploy the blog to many web hosts, like Heroku and Github Pages.

With Hexo we can write our posts using just a simple text editor and writing the content in Markdown syntax. Then the framework generate static HTML files based on the .md files and updates all the site structure.

In this article we are going to see how to start using this framework to easily create a new blog application.

Instalation

To get started with Hexo, we need to have Node.js and Git installed, because the framework is obtained from NPM and it downloads some files from a Git repository to create a new blog. Once you installed these two tools, you can check if they are really working in your computing by executing the command git --version for Git, node -v for Node.js and npm -v for NPM.

If everything is OK, you can install Hexo by runing a single command (in the Terminal/Command Prompt), that will install the Hexo Command Line Interface (CLI) from NPM:

npm install hexo-cli -g

The -g argument is used to install the package globally, so you can access it from any directory in your operational system.

When the installation finishes, you can check if the Hexo CLI is really available by runing the following command, which will show the framework version and environment informations:

hexo --version

From now on you can start working with the framework using the hexo command, which have many options and arguments to create and run a blog application, as we are going to see in the next session.

Creating a new blog

To create a new application with Hexo we have to run the init command, passing the name of the project in the <folder> argument. It will create a directory with this name, so we have to navigate to this folder and run npm install to restore the framework packages. In summary, we will need the following commands:

hexo init <folder>
cd <folder>
npm install

In the end of process, the application will be ready and you can start the embedded server by running the following command and then access it from the browser using the http://localhost:4000 URL.

To stop the server, you can press CTRL+C in the Terminal/Command Prompt and then type Y to confirm.

Creating a new post

By default, Hexo support Markdown syntax to write the blog posts, and for each post it creates a new .md file in the source/posts folder. To try it, execute the following command, passing the post’s title (it it has blank spaces, surround the title with quotation marks):

hexo new <title>

Now you can open the .md file that was created in the source/posts/ folder and edit it’s content using Markdown. For example, you can copy the Listing 1’s content to this file and save it:

---
title: Introduction to Hexo
date: 2016-11-26 16:17:57
tags: off-topic
---


Introduction
------------


This is my first blog created with Hexo.
Listing 1. Blog post example using Markdown

The first lines are added by default and indicates the main post settings: the title, the date/time when it was created, and it’s tags list.

Now, run the generate command, so Hexo will create the static files that will be delivered in runtime when the user access the blog:

hexo generate

If you start the server again, now you you are going to see the new post int he main page, as shown in Figure 1. In the right side there is also some links to the latest posts and tags.


Figura 1. First post in the blog

Now you can explore the other Hexo commands, change the template and deploy your blog to the production environment. Then, any time you need to create a new post, just run these commands again, write your post and deploy it again.



Microsoft MVP, Bachelor in Science And Technology, Editor and Consultant at DevMedia with more than 7 years of experience in software development.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login