gpt4 book ai didi

node.js - Heroku 找不到模块

转载 作者:太空宇宙 更新时间:2023-11-04 02:53:22 24 4
gpt4 key购买 nike

我试图在 Node 中请求一些 JS 文件,Localy - 效果很好,但在 Heroku 中我收到此错误 -

Error: Cannot find module './routes.js'

我的代码如下:

'use strict';

var express = require('express');
var app = express();

app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));

// Application Header
app.use(function(request, response, next) {
response.header('Access-Control-Allow-Origin', '*');
response.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
response.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, X-PINGOTHER');

next();
});

// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

console.log('./routes.js');
require('./routes.js')(app);

app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});

我做错了什么?谢谢!

最佳答案

您可以尝试运行 dyno 的一次性副本,让它列出目录内容 - 这将允许您检查文件是否位于您期望的位置。 (Heroku 有关于此 here 的更多信息。)例如:

heroku run 'ls -al'

这将导致 Heroku 创建(非常简单)应用程序的附加副本,并让它列出服务器上应用程序目录中的文件。您可能会发现您的 routes.js 文件不在您期望的位置。 (也许它没有 checkin git?)

如果您想进一步探索,请运行:

heroku 运行 bash

您的应用程序副本将拥有一个交互式 bash shell。从那里您可以查看文件系统,尝试在服务器上手动运行您的应用程序等。

关于node.js - Heroku 找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31214997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com