search

Home  >  Q&A  >  body text

javascript - How to separate front and backend using node?

I recently did a small exercise using express+ jade + mongodb. The jade template engine used needs to embed js logic code in the page code when rendering data. I personally don’t like this development model, so I would like to ask how to use node. Achieve complete separation of front and backend?

仅有的幸福仅有的幸福2781 days ago663

reply all(5)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:35:37

    The front-end and back-end separation pages must also be embedded js 代码啊,前端要跑的逻辑肯定还是得跑,express + jade Server-side rendering has been achieved, the front-end content is generated through the data rendering template, and the front-end then runs the corresponding front-end logic. This is considered complete separation.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:35:37

    Let node be only responsible for the backend, and jade can be thrown away.
    The front-end uses native js to perform an ajax request to obtain data, and then performs corresponding logical processing

    reply
    0
  • 迷茫

    迷茫2017-05-16 13:35:37

    Using express + mongodb, the URL can be mapped to the database
    ———— In other words, the URL is a pointer to the data.

    Adding a layer of jade to the express + mongodb technology means that the data must flow through jade, be coupled with the template into an html data stream, and then be returned to the client through response

    Separation of front-end and back-end means that the data taken out from the database is directly returned to response
    or processed by the template engine and then returned.

    (Experience: res.jsonres.render)


    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:35:37

    You can refer to Taobao’s front-end and back-end separation practice

    The details are subject to discussion, but the general pattern is clearly explained. As it says in it, it depends on how you want the "front-end and back-end separation" to be separated. And your understanding of the front-end.

    reply
    0
  • PHPz

    PHPz2017-05-16 13:35:37

    Replace the jade template with html and use ajax on the front end. It will be ok. . . (The front end is equivalent to static resources, nodejs can be regarded as a web server)

    reply
    0
  • Cancelreply