You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js遇Cannot GET /错误且MSSQL数据API故障的解决办法

Resolving "Cannot GET /" and MSSQL Connection Issues in Node.js Express API

The Problem

Recently, I ran into a couple of frustrating issues while building a Node.js Express API that pulls data from MSSQL:

  • When trying to hit the API endpoint, I got a Cannot GET / error
  • The API wouldn't run at all because the MSSQL connection kept failing

Here's the relevant code snippet from my project:

import express from "express";
var app = express();
var port = process.env.port || 1337;
var dbConfig = { 
  server:'123.123.12.1,1443', 
  database:'testingDB', 
  user:'userName', 
  password:'pass', 
  port:1433 
};

The Root Cause & Fix

After troubleshooting, I found the issue was in the MSSQL connection configuration: I was specifying the port number in two conflicting places—once appended to the server address in the server field (123.123.12.1,1443) and again in the separate port property set to 1433. This mix-up broke the database connection, which in turn prevented the Express server from initializing properly (that's why I saw the Cannot GET / error).

The fix was simple: don't include the port number in the server string. You can either keep the standalone port property or specify the port directly in the server string—but never both. For my setup, adjusting the dbConfig like this resolved all issues:

var dbConfig = { 
  server:'123.123.12.1', // Removed the port from the server address
  database:'testingDB', 
  user:'userName', 
  password:'pass', 
  port:1433 
};

Once the database connection started working, the Express API initialized correctly, and the Cannot GET / error vanished. A quick note: if you still see this error after fixing the DB connection, double-check that you've defined proper route handlers (e.g., app.get('/', (req, res) => { res.send('API is running!'); })) to handle incoming requests.

内容的提问来源于stack exchange,提问作者Raja Osama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:53:27