node.js - 值没有被插入到 PostgreSQL 数据库中

标签 node.js postgresql

我在 pgAdmin 4 上创建了一个数据库,但是当通过 Node 上的注册表单发送时,值没有更新。另外 npm install postgre-sql 给出了一个错误


    var express = require('express');
    var router = express.Router();
    const { Pool,Client} = require('pg')

    const connectionString='postgressql://postgres:12345@@localhost:5432/postgres'
    const client= new Client({
      connectionString:connectionString
    })

    client.connect()
    /* GET home page. */
    router.get('/', function(req, res, next) {
      res.render('index', { title: 'Express' });
    });
    router.post('/action',function(req,res){
      var uname= req.query.username;
      var pass= req.query.psw;
      var em= req.query.email;
      var DOB=req.query.dob;
      var gen= req.query.gender;

      client.query('INSERT INTO SIGNUP(username,email,password,DOB,gender) VALUES ("'+uname+'", "'+em+'", "'+pass+'","'+DOB+'","'+gen+'")',(err,res)=>{
        console.log(err,res)
        client.end()
      } )
    })
    module.exports = router; 

最佳答案

看起来你可能有错别字 postgressql://postgres:12345@@localhost:5432/postgres

应该是postgresql://postgres:12345@@localhost:5432/postgres

关于node.js - 值没有被插入到 PostgreSQL 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57521488/

相关文章:

node.js - 使用 shell 选项将 bash 与 Node.js child_process 一起使用失败

sql - 从 JSON 列计算平均值

postgresql - 多个窗函数的累加和

sql - 检查表是否继承自 PostgreSQL 中的其他表

node.js - 在 Node.js 中使用 WebSocket 的最简单方法

node.js - NodeJS的标准输出刷新?

node.js - 如何在 Electron 应用程序上正确存储 Google Drive API 的客户端 secret ?

postgresql - UPSERT Postgres 9.5

postgresql - 如何在 PostgreSQL 数据库中找到靠在一起的点?

node.js - 如何在nodejs中显示错误详细信息