小编Car*_*ine的帖子

NodeJS 和 Express:“错误:自签名证书”

我是 NodeJS 的初学者,我有一个非常简单的 Node/Express 应用程序,它使用 PostGreSQL 作为数据库。我的“db.js”文件如下所示:

const { Pool } = require('pg');

module.exports = new Pool({
    user: 'postgres',
    password: 'xxxx',
    host: 'localhost',
    port: 5432,
    database:'gymmanager'
});
Run Code Online (Sandbox Code Playgroud)

当我只在本地运行时,一切都工作正常,所以我决定将应用程序部署到 Heroku。为此,我使用我的开发环境变量创建了一个 .env 文件。这是 .env 文件:

NODE_ENV=dev
DB_USER='postgres'
DB_PASS='xxxx'
DB_HOST='localhost'
DB_PORT=5432
DB_DATABASE='gymmanager'
Run Code Online (Sandbox Code Playgroud)

我已经更改了我的“db.js”文件,现在看起来像这样:

if(process.env.NODE_ENV !== 'dev') {

    const { Client } = require('pg');

    const client = new Client({  
        connectionString: process.env.DATABASE_URL,
        ssl: true
    });

    client.connect();
    module.exports = client;

} else {

    require('dotenv').config();
    const { Pool } = require('pg');

    module.exports = new Pool({
        user: process.env.DB_USER, …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js npm express

6
推荐指数
1
解决办法
3万
查看次数

在Python中按值和键对字典进行排序?

我有以下字典:

dic = {'s': 3, 'a': 2, 'w': 2, 'y': 2, 'x': 2, 'm': 4, 'd': 5}
Run Code Online (Sandbox Code Playgroud)

我需要首先按 VALUE 对元素进行排序,如果值重复,然后按 KEY 排序,所以我会得到以下输出:

dic = [('d', 5), ('m', 4), ('s', 3), ('a', 2), ('w', 2), ('x', 2), ('y', 2)]
Run Code Online (Sandbox Code Playgroud)

我尝试过使用这段代码:

sorted(dic.items(), key=lambda x: x[1], reverse=True)
Run Code Online (Sandbox Code Playgroud)

但我不断得到相同的输出(键等于 2 的字母不是按字母顺序排列的):

[('d', 5), ('m', 4), ('s', 3), ('a', 2), ('w', 2), ('y', 2), ('x', 2)]
Run Code Online (Sandbox Code Playgroud)

有谁知道我该如何解决这个问题?

提前致谢。

python dictionary

4
推荐指数
1
解决办法
71
查看次数

如何在 Try/Catch 块内抛出异常?

我有以下 Java 方法:

public Class createClass(Class class) {
    try {
        // retrieve the professor of the class and check if he exists
        Professor professorFound = professorRepository.findById(class.getProfessorId());
        if (professorFound != null) {
           // if the professor exists, then check if he already has a class
           // with the same id
           List<Class> classes = professorFound.getClasses();
           List<Class> classFound = classes.stream().... // loop to find the class... 

           // if he has, throw an exception
           if(!classFound.isEmpty()) {
                throw new ClassAlreadyRegisteredException();

           } else {
                // if …
Run Code Online (Sandbox Code Playgroud)

java spring-boot

1
推荐指数
1
解决办法
264
查看次数

标签 统计

dictionary ×1

express ×1

java ×1

node.js ×1

npm ×1

postgresql ×1

python ×1

spring-boot ×1