[英]How to develop a multi-tenant application with Node.js (express.js)?
[英]Is it necessary the express.js framework to develop nodeJS web application
我正在嘗試使用HTML,NodeJS和Postgres開發簡單的Web應用程序。 是否可以在不使用ExpressJS的情況下開發Web應用程序。 請告訴我如何使用NodeJs,Javascript和Postgres進行基本的CURD操作,而不使用ExpressJS框架。 提前致謝。
是的,你可以跳過快遞但這不容易。
但還有別的東西:
是否可以在不使用ExpressJS的情況下開發Web應用程序
這可能意味着,
在第一種情況下,您可以選擇。 有像hapi,Flicker.js等MVC框架,REST API框架,如restify,loopback等
在第二種情況下,您將面臨編寫Express提供的許多功能的自定義實現的工作。
我繼續假設你的意思是第二個案例......
要創建HTTP服務器,可以使用節點的HTTP模塊
var http = require('http');
http.createServer(function (req, res) {
res.write('Hello World!');
res.end();
}).listen(8080);
這種方法使編寫REST API變得很麻煩
req.url; //the request URL
if(url == '/users/create')
{
//do this
}
else if(url == '/users/details')
{
//do that
}
要連接到postgres,你必須使用node-postgres(pg)( pg文檔 )
const { Client } = require('pg')
const client = new Client()
await client.connect()
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
await client.end()
至於CRUD操作,除了API實現之外,代碼幾乎是一樣的。 所以你可以參考使用express的教程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.