第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

這個(gè)Javascript“要求”是什么?

這個(gè)Javascript“要求”是什么?

慕娘9325324 2019-07-01 15:01:32
這個(gè)Javascript“要求”是什么?我試圖讓Javascript讀取/寫入PostgreSQL數(shù)據(jù)庫(kù)。我發(fā)現(xiàn)了這個(gè)工程項(xiàng)目在GitHub上。我能夠在節(jié)點(diǎn)中運(yùn)行以下示例代碼。var pg = require('pg'); //native libpq bindings = `var pg = require('pg').native`var conString = "tcp://postgres:1234@localhost/postgres";var client = new pg.Client(conString);client.connect();//queries are queued and executed one after another once the connection becomes availableclient.query("CREATE TEMP TABLE beatles(name varchar(10), height integer, birthday timestamptz)");client.query("INSERT INTO beatles(name, height, birthday) values($1, $2, $3)", ['Ringo', 67, new Date(1945, 11, 2)]);client.query("INSERT INTO beatles(name, height, birthday) values($1, $2, $3)", ['John', 68, new Date(1944, 10, 13)]);//queries can be executed either via text/parameter values passed as individual arguments//or by passing an options object containing text, (optional) parameter values, and (optional) query nameclient.query({   name: 'insert beatle',   text: "INSERT INTO beatles(name, height, birthday) values($1, $2, $3)",   values: ['George', 70, new Date(1946, 02, 14)]});//subsequent queries with the same name will be executed without re-parsing the query plan by postgresclient.query({   name: 'insert beatle',   values: ['Paul', 63, new Date(1945, 04, 03)]});var query = client.query("SELECT * FROM beatles WHERE name = $1", ['John']);//can stream row results back 1 at a timequery.on('row', function(row) {   console.log(row);   console.log("Beatle name: %s", row.name); //Beatle name: John   console.log("Beatle birth year: %d", row.birthday.getYear()); //dates are returned as javascript dates   console.log("Beatle height: %d' %d\"", Math.floor(row.height/12), row.height%12); //integers are returned as javascript ints});//fired after last row is emittedquery.on('end', function() {    client.end();});接下來(lái),我試圖讓它在網(wǎng)頁(yè)上運(yùn)行,但似乎什么也沒(méi)有發(fā)生。我查看了Javascript控制臺(tái),它只說(shuō)“RequireNotDefined”。那么這“要求”是什么呢?為什么它在節(jié)點(diǎn)中工作,而在網(wǎng)頁(yè)中卻不起作用?而且,在我讓它在節(jié)點(diǎn)上工作之前,我必須做npm install pg..那是怎么回事?我查看了目錄,沒(méi)有找到PG文件。它把它放在哪里,Javascript是怎么找到它的?
查看完整描述

3 回答

?
牛魔王的故事

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊

它用來(lái)裝載模塊。讓我們用一個(gè)簡(jiǎn)單的例子。

存檔circle_object.js:

var Circle = function (radius) {
    this.radius = radius}Circle.PI = 3.14Circle.prototype = {
    area: function () {
        return Circle.PI * this.radius * this.radius;
    }}

我們可以通過(guò)require,比如:

node> require('circle_object'){}node> Circle{ [Function] PI: 3.14 }node> var c = new Circle(3){ radius: 3 }node> c.area()

這個(gè)require()方法用于加載和緩存JavaScript模塊。因此,如果要將本地相對(duì)JavaScript模塊加載到Node.js應(yīng)用程序中,只需使用require()方法。

例子:

var yourModule = require( "your_module_name" ); //.js file extension is optional


查看完整回答
反對(duì) 回復(fù) 2019-07-01
  • 3 回答
  • 0 關(guān)注
  • 367 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)