我正在使用Google Cloud vm实例运行我的节点应用程序,并且我已经安装了Ubuntu 16.04.6,已经安装了nodejs v11.10.1和npm v6.7.0,但是当我使用node app
运行应用程序时,它显示为{ {1}}。我不知道这里出了什么问题。
这是我的package.json文件:
ReferenceError: post is not defined
这是我的发布路线:
{"name": "name",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"deploy":"gcloud app deploy"
},
"author": "Faiz Khan",
"license": "ISC",
"dependencies": {
"bson": "^4.0.1",
"connect-mongo": "^2.0.3",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-session": "^1.15.6",
"fabric": "^2.4.4",
"jquery": "^3.3.1",
"mongodb": "^2.2.33",
"mysql": "^2.16.0",
"node-fetch": "^2.3.0",
"npm": "^6.4.1",
"redis": "^2.8.0",
"socket.io": "^2.0.3"
}
}
这是错误:
app.post('/chat',(req,res,next) =>{
userName = req.body.usrnm.toUpperCase();
res.render('classLayout',{user:userName});
});
该应用程序可以在macOS上的localhost上运行良好,甚至在heroku上也可以,但是它只会在ubuntu上造成问题
答案 0 :(得分:0)
您需要全局安装nodemon软件包才能在CLI中的任何目录中访问它。 为此,以下是您需要执行的命令。 :
npm install -g nodemon
对于您的“发布”错误,您需要共享app.js或路由文件中存在的代码段。
答案 1 :(得分:0)
package.json
没有nodemon
具有dev依赖关系,并且尚未将其安装在计算机上。
npm install --save-dev nodemon
,这会将“ devDependencies” 添加到package.json "preinstall": "npm i -g nodemon",
package.json
{
"name": "name",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"preinstall": "npm i -g nodemon",
"start": "node app.js",
"deploy": "gcloud app deploy"
},
"author": "Faiz Khan",
"license": "ISC",
"dependencies": {
"bson": "^4.0.1",
"connect-mongo": "^2.0.3",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-session": "^1.15.6",
"fabric": "^2.4.4",
"jquery": "^3.3.1",
"mongodb": "^2.2.33",
"mysql": "^2.16.0",
"node-fetch": "^2.3.0",
"npm": "^6.4.1",
"redis": "^2.8.0",
"socket.io": "^2.0.3"
},
"devDependencies": {
"nodemon": "^1.18.10"
}
}
现在,当您部署到其他计算机或其他开发人员参与其中时,唯一需要执行的是npm install