用 express
相对于直接用 nodejs
建站的好处在哪?
express
用的是 jade
格式的模板,可以直接用 html 文件吗?
jade
位于 express
项目的 views
文件夹下,为什么看到其他地方的人回答:“要是用 html 代替 jade
,要放在 public 文件夹,但是页面就变成静态的了”,静态网页与动态网页的区别?
使用 nodejs
的互联网公司,也是用 express
框架吗?也是用的 jade
吗?
一般什么情况下用静态网页,什么情况下用动态网页?
个人博客需要数据库吗?只是在上面写一些文章附带一些图片,如果用使用 mongodb
还是 MySQL
?
2016/5/31 22:49 增加的:
7.写博客直接在html文档里写?还是用innerHtml()?还是用其他方法?
会用html html5 css css3 javascript jquery。nodejs本地实验过,不过不真正在服务器上跑起来感觉离会还很远呀,比较新的网上盛传的nodejs学习文档基本看过一遍。最近自己利用fanqiang的vps主机简单搭了一个express,远程访问成功了。博客雏形早就写好了,用的标准html+css+javascript+jquery切页面,本来想直接用nodejs启个服务,但是看到网上基本都是express做的,很少直接用nodejs。于是打算把做的雏形和express结合。又遇到jade、ejs这些问题,有点困惑。
ringa_lee2017-04-17 13:57:54
You just don’t have to think about it so much. For routing and the like, it is recommended to use a framework
Yes, you can take a look at swig
This does not affect it. In the final analysis, it is just a template engine or a page rendered by node. Simply put, a static web page is accessing an existing file. Dynamic means dynamic rendering, such as reading data from the database and rendering.
I don’t know much about it, but I guess I use it a lot
The nature of the display will not change for a long time. For example, h5 pages and the like (display), it depends on your needs. If the blog is like hexo, it will be static, if it is similar to wordpress, it will be dynamic. It depends on your needs
The hexo mentioned above is static. Simply put, node renders data to generate html files and hosts them in places like pages. It depends on the needs. It can be done both ways. Both mongodb and mysql seem to be fine. It doesn’t matter, it mainly depends on what you make
ringa_lee2017-04-17 13:57:54
"Your problem is mainly that you don't write enough code and think too much" - Albert Einstein
The role of the framework is usually to simplify some common functions, saving users time and paying attention to every detail
Express can use Jade, EJS, Swig, Handlebar and other HTML templates
Resolutely resist interference from people including but not limited to product managers, designers, bosses, etc. on where programmers like to put files
It’s useful
Can be used or not. You can use MongoDB or MySQL
高洛峰2017-04-17 13:57:54
There are the following ways to create a blog using node (the same applies to other languages):
1. The most original method: does not apply to any framework, that is, not even express. Complete slash and burn farming.
2. The more primitive way: use a framework, but you still need to code it yourself. You are not allowed to write each page by yourself?
If you are practicing and learning techniques, you can use the above two methods, otherwise it is recommended to use the following advanced method
3. Advanced method: use mature blogging framework. No need to write any code. Just write blog content and publish it. Recommend a node blog framework https://github.com/hexojs/hexo
This is my blog: http://www.liyanshan.com/
Completely static. .
迷茫2017-04-17 13:57:54
1. Express is based on the http module of nodejs, with a higher abstraction level. There are currently many mature examples of engineering resource management methods. Whether it is good or not cannot be summed up in one word. People with different technical levels have different experiences.
2. Express can specify templates, and the official documentation provides detailed instructions. For details, see
http://www.expressjs.com.cn/guide/using-template-engines.html
3. Static Web pages and dynamic web pages depend on whether data can be exchanged with the server when used.
4. What framework does the Internet company use? It doesn’t have to be express. Restify and koa are also possible. It is also possible to build a wheel based on your own needs.
5. When the front-end and back-end interact with a large amount of data, use dynamic web pages. The demand for dynamic web pages for personal blogs is not rigid.
6. Personal blog, generally speaking, static pages are enough. You write articles, bring some pictures, and use the database to meet elastic needs.
7. I wonder how much personal knowledge reserve you have? For example, knowledge about the http protocol in computer networks, the http module of the nodejs module, and how much you know about NoSQL and SQL.
8. For your personal blog website, did you do everything yourself from visual design, UI interaction design, to front-end code, to back-end code to database design? Or should the front-end use a framework, the back-end also use a framework, and the visual design reuses other people’s designs?
9. To build a personal blog website, you can use a mature CMS, such as wordpress. Or GEEK, use GitHub Pages + Hexo (Jekyll)
10. My blog is completely static: sky111144.github.io, based on GitHub Pages + Hexo
天蓬老师2017-04-17 13:57:54
What are the advantages of using express versus directly using nodejs to build a website?
The advantage of using a framework is that it is "fast", because in most cases the problems that may be encountered in specific projects have already been taken into account by the framework. For example: The express
design of middleware
makes it easy to record public logs, global error handling, cache control, and authentication.
Express uses jade format templates, can I use html files directly?
Sorry jade
is a shorthand syntax, you cannot write html
directly in it. If you want to write html
syntax directly, try changing the template engine to ejs. Reference document using-template-engine
jade is located in the views folder of the express project. Why do people from other places answer: "If you use html instead of jade, you have to put it in the public folder, but the page becomes static." Static What is the difference between a web page and a dynamic web page?
Indeed, static files are usually placed directly in the public
directory. Generally speaking, static web pages are the same for everyone to see; but dynamic web pages can display different content according to different viewers; the same template can also be used to provide users with multiple readings by injecting different variables. For example: when super administrators, ordinary administrators, and ordinary users look at the same page, they will definitely see different content.
Do Internet companies that use nodejs also use the express framework? Are you also using jade?
express
The framework is indeed used by many users because of its simplicity and ease of use. But it is by no means the only one. Other well-known frameworks include: koa, toa. . . In fact, there are many!
It’s hard to say whether everyone uses jade
. Personally, I think there are quite a few who use ejs
When are static web pages generally used and when are dynamic web pages used?
Usually the company's homepage (which is the page that introduces the company's business and displays the boss's style) is static, because there is no need to "adjust the content according to the viewer" and "the same template does not need to adapt to different content." In the rest of the cases, it’s mostly dynamic. For example: segmentfault
's "Article" column is a template, but when you click on each article, you will see the content of that article, rather than every article looking the same.
Does a personal blog need a database? I just wrote some articles with some pictures. Should I use mongodb or MySQL?
It’s really not necessary. Websites such as github
and coding
can host personal blogs. I have written a small tutorial before to set up a blog on Github
巴扎黑2017-04-17 13:57:54
As a half-assed person who has worked in an Internet company for a month and is currently unable to find an internship, let me answer this forcefully
What are the advantages of using express compared to directly using nodejs to build a website?
Simplified code, omitting many (actually not many) things
Express uses jade format templates, can I use html files directly?
express
supports many engines, jade
is just one of them, and (it used to be, but I don’t know now) html
is also one of them
jade is located in the views folder of the express project. Why do people from other places answer: "If you use html instead of jade, you have to put it in the public folder, but the page becomes static." Static What is the difference between a web page and a dynamic web page?
Regarding static and dynamic, you can refer to my nonsensical blog post. Since I am not a professional, there will be many mistakes in it. You can probably make sense of it public
The static files in the folder will not change, and the templates under view
will display different pages (such as segmentfault’s homepage) according to the data passed in during rendering
Do Internet companies that use nodejs also use the express framework? Are you using jade too?
It can be express
The company I worked for before was express
+ejs
, and the rest architecture express
+JSON
+angularjs
When are static web pages generally used and when are dynamic web pages used?
Generally speaking, use static web pages that do not need to be changed for a long time (because it saves resources), and use dynamic web pages that change frequently
In fact, it is up to you to use them however you want
Does a personal blog need a database? Just write some articles with some pictures. If you use mongodb or MySQL?
Need or not, the database is just an option.
Typical blogs that use databases include wordpress, and those that do not use databases include hexo
Static blogs cannot use databases
The choice between mongodb
and mysql
is actually not important. It just depends on your mood and proficiency.
Writing a blog directly in the html document? Or use innerHtml()? Or use other methods?
The writing method for dynamic blogs like wordpress is similar to posting on segmentfault. You finish writing and submitting in an input box.
For similar hexo, you write the markdown file in your own editor, and then hexo will Convert it to html
As for server-side rendering, it is probably similar to generating a whole block of html, in which the specified positions are your customized content, such as rendering templates like this in routing
//route
res.render("hello.html", {
var: "Hello"
});
<!-- hello.html -->
<h1>{{ var }}</h1>
Then the client will get this piece of HTML
<h1>Hello</h1>
Finally, here is my blog
There is also a blog that I am currently working on
By the way, I want to take my summer internship in Chengdu with me_(:3)JL)_
高洛峰2017-04-17 13:57:54
In fact, hexo is also sufficient. Writing blogs with Markdown is actually very convenient and fast
高洛峰2017-04-17 13:57:54
1. Express has powerful routing functions and rich data processing. It can save you a lot of trouble
2. Yes, the suffix does not matter, but you need to change the corresponding parameters in the template configuration
3. The public folder is express’s default static resource processing folder. You can also change to other ones, which are all static resources. Dynamic web pages are pages generated by the program after fetching data from the database based on responses
4. Each company has its own business logic.
5, hard to answer, not all pages are dynamic, you can also dynamically generate static pages.
6. Personal blog, if there is not much data, you can use json as a database. There are many differences between MySQL and MongoDB. The choice of database depends on your business logic
阿神2017-04-17 13:57:54
Just a side note, my personal opinion is rather one-sided.
What is your first goal in organizing?
If you are blogging, concentrate on writing. Many people write blogs in order to build a personal website. As a result, they spend all their time on coding and only write a few articles on the blog. There are already many ready-made blog tools. There are those with a server (a machine is required), and there are purely static ones (just send them to github). Personally, I prefer the second one. Recommend a tool MWeb.
If you want to learn code, buy a few books and read them in a down-to-earth manner. There are now a lot of nodejs books. Find a framework, as long as it is of that magnitude, it is good. Use it first. After all, you will only know the specific quality after using it (it varies from person to person, right?)
Be conservative and express, and build it yourself. I'm tired. Let's go through the door first and then go deeper. The radical thing is koa, a framework with good ideas, don’t use it if you don’t have two brushes.
Use ejs for the same reason, don’t use jade if you don’t have two brushes
ringa_lee2017-04-17 13:57:54
Framework can save code. However, since node comes with its own http module, the code that can be saved is very limited. This requires you to make your own choice. There is nothing wrong with manually taking the querystring of req and building your own routing table.
However, the template engine cannot be omitted at all. If you splice html yourself, various security risks will arise.
You can use app.engine to define the template engine and res.render for rendering. You can also bypass res.render and call the engine directly. For html, you can directly read it with fs and flash it to res.
The directory does not matter, they are all configurable. Express's template module can distinguish templates by suffix and will not mix them. Static pages have no input and output is constant.
It is estimated that some do not use frames. The mainstream choice of template engine in the community is ejs.
Required. Choose rdbms or nosql based on your personal preference. Generally speaking, NoSQL is easy to write but difficult to maintain.
For any UI or interaction issues, refer to wordpress and typecho.