Hello.
I’ve been trying to deploy a nodejs app, but I’m having some issues.
I’m using a free instance, since I’m learning how to deploy this kind of stuff.
This app is a rest api using koa and has a postgres database, which is a neon
service.
The build worked fine, but error happens when is trying to start the service.
The logs shows that it is unable to bind to a port, but I’m sure the app is getting the value from process.env.PORT
.
I’m using winston as logger, but logs do not help very much.
Is there an away to get a more detailed log?
Or my logger is setup wrong?
INFO==> Deploying...
INFO==> No open ports detected, continuing to scan...
INFO==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
INFODeploy cancelled
INFO==> No open ports detected, continuing to scan...
INFO==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
INFO==> Running 'npm start'
INFO
INFO> app@0.1.0 start
INFO> node dist/server.js
INFO
ERROR2024-05-14 03:13:35.499 error [99] Failed to initialize data source. Reason: error: connection is insecure (try using `sslmode=require`)
INFO==> Using Node version 20.12.2 (default)
INFO==> Docs on specifying a Node version: https://render.com/docs/node-version
INFO==> Using Bun version 1.1.0 (default)
INFO==> Docs on specifying a bun version: https://render.com/docs/bun-version
INFO==> Running 'npm start'
INFO
INFO> app@0.1.0 start
INFO> node dist/server.js
INFO
INFO==> No open ports detected, continuing to scan...
INFO==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
ERROR2024-05-14 03:14:18.988 error [80] Failed to initialize data source. Reason: error: connection is insecure (try using `sslmode=require`)
INFO==> Using Node version 20.12.2 (default)
INFO==> Docs on specifying a Node version: https://render.com/docs/node-version
INFO==> Using Bun version 1.1.0 (default)
INFO==> Docs on specifying a bun version: https://render.com/docs/bun-version
INFO==> Running 'npm start'
INFO==> No open ports detected, continuing to scan...
INFO==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
INFO
INFO> app@0.1.0 start
INFO> node dist/server.js
INFO
ERROR2024-05-14 03:15:28.897 error [79] Failed to initialize data source. Reason: error: connection is insecure (try using `sslmode=require`)
INFO==> No open ports detected, continuing to scan...
INFO==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
INFO==> Using Node version 20.12.2 (default)
INFO==> Docs on specifying a Node version: https://render.com/docs/node-version
INFO==> Using Bun version 1.1.0 (default)
INFO==> Docs on specifying a bun version: https://render.com/docs/bun-version
INFO==> Running 'npm start'
INFO
INFO> app@0.1.0 start
INFO> node dist/server.js
INFO
INFO==> Port scan timeout reached, no open ports detected. Bind your service to at least one port. If you don't need to receive traffic on any port, create a background worker instead.
INFO==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
ERROR2024-05-14 03:17:19.392 error [80]
this is my settings.ts
import os from "os";
import path from "path";
import * as pkg from "../../package.json";
import { ISettings } from "../types";
const env = process.env.NODE_ENV || "development";
const port = (env !== "test") ? (Number(process.env.PORT) || 3000) : 0;
export const settings: ISettings = {
env: env,
test: (env === "test"),
development: (env === "development"),
name: pkg.name,
version: pkg.version,
port: port,
storage: process.env.STORAGE || path.join(os.tmpdir(), pkg.name),
logger: {
level: "INFO",
time_zone: "America/Sao_Paulo"
},
database: {
host: process.env.DB_HOST || "localhost",
port: Number(process.env.DB_PORT) || 5432,
user: process.env.DB_USER || "postgres",
pass: process.env.DB_PASS || "postgres",
name: process.env.DB_NAME || "default"
}
// jwt: {
// secret_key: process.env.JWT_SECRET_KEY || "x",
// expiration: process.env.JWT_EXPIRATION || "12h"
// }
};
this is my logger.ts
import winston from "winston";
import colors from "@colors/colors/safe";
import { TransformableInfo } from "logform";
import { DateTime } from "luxon";
import { settings } from "./settings";
const { test } = settings;
const formatter = (info: TransformableInfo, opts?: any) => {
const { timestamp, level, message, ...args } = info;
const tz = DateTime.fromISO(info.timestamp).toFormat("yyyy-MM-dd HH:mm:ss.SSS");
const text = [
colors.magenta(tz),
info.level,
colors.gray(`[${process.pid}]`),
colors.gray(info.message)
].join("\t");
return colors.gray(text);
};
// Define the Winston logger configuration
export const logger = winston.createLogger({
silent: test,
level: "info",
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.printf(formatter)
),
transports: [
new winston.transports.Console()
// new winston.transports.File({ filename: "logs/error.log", level: "error" }),
// new winston.transports.File({ filename: "logs/application.log" })
]
});
update:
this post suggests to set hostname to “0.0.0.0”, however I’ve still got the bind port error.