I was a liberal arts majors mid-career front-end developer, from the original can only cut the figure and write the CSS and Html to now will write JS, bumpy all the way, is also a lot of experience, since 2010 with WordPress opened his own blog, although content assorted is not much, but also left a microcosm of time more or less, I always wanted to have a plot of my own. The idea of using Node.js as a server to replace WordPress was put on hold last year due to lack of time. Of course the WordPress as global users the most popular open source blog program, ease of use, and many other advantages, can light your blog in the past few years with a lot of set of templates, also use it to do too many different functions of different style website, perhaps Node. Js the best development language choice is not a personal blog, whether feelings or other, I’m sure there are front-end developers out there who have thought about trying this. On the market a lot of open source blog program, UI template is quite pretty, but to develop a belong to their own blog program, it’s okay when STH over and over again, would be a more beautiful thing, the main purpose is in the process of its works, has been developed to try to the service functions, the stack from a pure front end to all development engineer is a very good practice. Git has a lot of open source Node.js source code, the tutorial is more detailed, some comprehensive functions, some relatively simple, of course, everyone just choose their own good, the following brief introduction of my project, from the technical point of view, the depth is limited, big god many suggestions.

architecture

The project follows the traditional MVC, relatively old architecture, model(object model), View (view), controller (controller), model is generally the mapping of database table fields, View is the interface, UI,controller is the operation of the database, generally receive routing information, The database is then manipulated and the data is returned to the View layer. Developers familiar with the backend may understand this at a glance, but pure front-end developers who have not done back-end development may take some time to digest. I remember the first time I did full-stack development, which was a project to store CCTV configuration data. It was based on c# and sqlserver, and it was also a standard MVC architecture. It was very simple to add, delete, change and check, which wasted a lot of effort.

The database

MongoDB is used for database, why it is used, because it is easy to use, and it is the most functional in non-relational data, the most like a relational database. Mongoose is used to operate the database. The API is easy to read and easy to use. I used to use mysql for wordpress, there is no special method or tool to export data to MongdoDB, I tried to use some tools and scripts, the efficiency is not high, and finally finished by hand, fortunately I am lazy, so there are few contents for so many years.

WEB frameworks and templates

The page rendering part is handlebars template. Personally, I feel that {{}} curly braces are more suitable for front-end developers. However, Handlebars template is a weak logic language, which has some disadvantages. However, if you prefer an HB template, you can go to the git helper library. The Jade template (now changed to PUG) is more convenient and efficient for processing some complex logic. The main thing is that you can write JS syntax directly in the template, but the indentation is not something that every front-end developer can get used to.

The front end

Today’s front and back end separation, MV* framework, engineering, modular, these concepts are popular, if a front-end does not know these concepts, I am afraid that it is difficult to find work. However, this project did not separate the front and back ends, rendering the page directly at the back end, nor did it use the MVVM framework, not to mention engineering and modularization. The background page used a jQuery, BootStrap and some plug-ins, and the front page seemed to be just a jQuery, CSS basic handwriting, I believe it will be more friendly to the front-end developers. My original intention is to learn more about back-end development ideas and patterns through this project. Secondly, personal blog is a source of communication, and back-end rendering is also conducive to SEO.

The principle of

When you open a page on your blog, Node.js uses a routing mechanism (a routing module provided by Express) on the back end to match the URL to the page. Then look up the corresponding controller (the function that handles the URL). In this controller function, do some filtering of the database (using Mongoose to operate on the database) and finally get the data needed for the page. Then pass the data to the corresponding template (Handlebars). The final rendering is HTML.

Due to the short time, the functions of the blog may be relatively simple, but the basic functions have been met. In addition, there are many functions and interfaces that are not used in the project, so there is no time to sort out, so I will leave it for later expansion. This is my blog at github.com/frogo/blog. Welcome star and fork.

Screenshot