简体   繁体   English

在heroku master上推送nodejs应用

[英]pushing nodejs app on heroku master

I've created a server for my front end project using nodejs on the back end. 我已经在后端使用nodejs为前端项目创建了服务器。 after testing it successfully on my computer(localhost:3001),I wanted to deploy it on heroku. 在我的计算机(localhost:3001)上成功测试之后,我想在heroku上部署它。

to do so, I ran the following codes on gitbash(windows) : 为此,我在gitbash(windows)上运行了以下代码:

1-git init
2-git add .
3-git commit -m "my 1st commit"
4-heroku create 
5-git remote -v
6-heroku rgit:remote -a blah-blah-21222
7-git push heroku master 

here's the error I stumbled upon : 这是我偶然发现的错误:

! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/blah-blah-21222.git'

I even changed the last line of my codes on server.js Which initially was : 我什至更改了server.js的代码的最后一行,该行最初是:

app.listen(3001,()=>{
    console.log('app is running on port 3001');
})

and switched it to : 并将其切换为:

app.listen(process.env.PORT||3001,()=>{
    console.log(`app is running on port ${process.env.PORT}`);
})

I got the same error as well and I don't feel like if this port change is the main challenge in the first place. 我也遇到了同样的错误,并且我不认为此端口更改首先是否是主要挑战。

Do you have any idea how I can deploy this nodejs server on heroku ? 您是否知道如何在heroku上部署此nodejs服务器?

You should create a named app with command : 您应该使用以下命令创建一个命名应用

heroku create blah-blah-21222  // blah-blah-21222 is name you want (not duplicate)

When you use: 使用时:

heroku create

heroku create random name for you, please sure thas name is blah-blah-21222 Try it and see any error ? heroku为您创建一个随机名称,请确保名称是blah-blah-21222尝试一下,看看是否有错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM