導航:首頁 > 編程語言 > nodejs訪問postgresql

nodejs訪問postgresql

發布時間:2025-01-28 11:58:35

① sails 多維json怎麼遍歷

一、安裝時:

先裝nodejs,成功標志 node -v

安裝sails 全局安裝 node install sails@version -g 安裝成功 sails -v

創建 項目 sails new projectname

安裝grunt : npm install grunt@version --save-dev(在項目的目錄中)

啟動sails服務:sails lift

在啟動時提示的錯誤,可以用 npm install 在當前的項目下進行安裝。

在創建api時用命令:sails generate api book(在安裝後很可能sails lift時會出現錯誤,此次的處理是npm install sails-config --save-dev

測試瀏覽:http://localhost:1337/user 創建http://localhost:1337/user/create?name=xy&password=fc12345

note:to avoid the migration warning from sails when generating the book api,add the following to config/env/development.js

models:{

migrate:"alter"

}

二、文件夾:

assets下可以放直接被url調用的網頁,圖片,js,等文件,url http://localhost:1337/在assets下的路徑。

三、路由

config/routes.js

'/':{view:'homepage'} localhost:1337

'/about':{view:'about'} localhost:1337/about 在views下創建 about.ejs

路由藍圖包括以下三種:

restful路由

These routes always have the path of /:modelName or /:modelName/:id

and send the request to the appropriate action by using the HTTP "verb".Middleware policies should be used in a proction environment to protect these routes fromuauthorized access.

shortcut路由

these routes only respod to "get" requests and determine which action to send the request to by decoding the path.An example path would look like

/:modelName/<action> and data would be passed to the controller action using query parameters. While great for development work o a prototype,these routes should be disabled in proction.

action路由

Thes routes create shortcut routes for custom actions tat don't come for free as part of the restful routes.So for any custom action on a controller,a corresponding path followingthe format /:controllerName/:actionName whill respond to get requests and send the request to the controller.

Blueprit Actions

The Blueprint API creates a number of generic actions tohandleall of the standard behaviour of a restful JSON API to match the BluePrint routes.The following default controller actions,which can be overridden,are provided by the Blueprint api:

find findOne create update destory populate add remove

如何使用 http verb?

'get /posts':{

controller:'postsController',

actio:'list'

}

這個配置告訴應用對get 的請求做出回應,在url處理方式為postscontroller下的list操作。

『put /posts/:id':{

controller: 'postsController',

action:'update'

}

這個配置對put請求做出回應,更新一個已存在的用戶,其中id為參數,update是postsController中的一個操作。

如何更改模板?

1.用jade 代替 Ejs

npm install jade --save

更改config/views.js文件:

mole.exports.views={

engine:'jade',

layout:fasle,這個只有ejs支持,所以換成jade後,要把layout設為false;

locals:{//any options you would like to pass to the jade parser}

}

最後從package.json中移走ejs;

樣式文件的替換用sass 替換 less

1.把grunt-contrib-less從age.json中移走,npm install grunt-contrib-sass --save

2.改變所有Grunt task 中的less 引用為 sass.(需要改變的有如下文件)

tasks/cofig/.js

tasks/register/compileAssets.js

tasks/register/syncAssets.js

其實如果是新項目了只需更改 tasks/importer.less為importer.sass,其它的都由Sass自動適配。

用postgres 代替LocalDB

waterline (與許多流行的資料庫一起工作)(如:Postgresql,MongoDB,Redis.)

② 詳解離線安裝npm包的幾種方法

離線安裝npm包可以在沒有互聯網連接或者需要更好的安全性時派上用場。以下是幾種離線安裝npm包的方法:
1. **使用離線npm包文件:**
- 在有互聯網連接的機器上,使用`npm pack`命令將所需的npm包打包成`.tgz`文件。例如:`npm pack package-name`。
- 將生成的`.tgz`文件復制到目標機器。
- 在目標機器上使用`npm install`命令來安裝本地的`.tgz`文件,例如:`npm install package-name-1.0.0.tgz`。
2. **使用本地npm緩存:**
- 在有互聯網連接的機器上,使用`npm install`命令來安裝所需的npm包,它會默認將包緩存到本地。
- 復制本地npm緩存文件夾(通常是`~/.npm`或`%AppData%/npm-cache`)到目標機器的相同位置。
- 在目標機器上運行`npm install package-name`來安裝包,npm會檢查緩存並使用緩存的包。
3. **使用離線npm工具:**
- 有一些工具可以幫助你在沒有互聯網連接的情況下安裝npm包,例如`npm-offline`、`cnpm`等。你可以在有互聯網連接的機器上使用這些工具來下載依賴包,然後將它們復制到目標機器並運行工具來安裝。
4. **使用yarn離線模式:**
- 如果你使用yarn而不是npm,yarn提供了一種離線模式,可以在沒有互聯網連接時使用。在有互聯網連接的機器上使用`yarn`來安裝依賴,然後將`~/.yarn-offline-mirror`文件夾復制到目標機器,並在目標機器上運行`yarn install --offline`。
請注意,離線安裝npm包可能會涉及到版本兼容性和依賴問題,因此在離線環境中要特別小心。最好在有互聯網連接的機器上測試包的安裝,然後再將它們復制到離線機器上。此外,確保你獲得了所有需要的依賴項和正確的版本,以避免潛在的問題。

閱讀全文

與nodejs訪問postgresql相關的資料

熱點內容
發送手機里的錄音文件在哪裡 瀏覽:866
js獲取下一個兄弟元素 瀏覽:293
js模板引擎原理 瀏覽:72
linuxo文件運行 瀏覽:713
什麼免費備份數據 瀏覽:342
測量大師導入底圖找不到文件 瀏覽:313
小紅傘安裝程序要求版本6 瀏覽:799
全民k歌pcm文件夾 瀏覽:224
c圖片寫入資料庫 瀏覽:466
c串口程序 瀏覽:500
中農金融注冊app有哪些 瀏覽:629
回收站文件清理不在電腦上有痕跡 瀏覽:886
dx版本更新 瀏覽:738
主機集群教程 瀏覽:939
蘋果6英版好不好 瀏覽:959
nodejs抓取網站音頻 瀏覽:772
app上下載的軟體在哪裡 瀏覽:36
起凡保存的照片在哪個文件夾 瀏覽:354
數學建模如何把模型編程 瀏覽:176
ug找不到指定的許可文件 瀏覽:850

友情鏈接