我是新来的“小橙”,我试图运行在小橙色的快递应用程序this link
我首先创建了以下目录结构
/ home / user / servercode / myapp 与 tmp 目录和 app.js 文件 / home / user / public_html / clientCode / myapp 与.htaccess
/ home / user / servercode / myapp / tmp 包含一个空的 restart.txt 文件在 / home / user / servercode / myapp 中,我运行
npm init
npm install express --save
这是我的 app.js。与帖子中提到的链接中的几乎相同
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World Express App');
});
if (typeof(PhusionPassenger) != 'undefined') {
console.log( 'Example app listening with passenger' );
app.listen('passenger');
} else {
console.log( 'Example app listening with 3000' );
app.listen(3000);
}
.htaccess 有 644 权限级别,并包含此
PassengerEnabled on
PassengerAppRoot /home/user/serverCode/myapp
SetEnv NODE_ENV production
SetEnv NODE_PATH /usr/lib/node_modules
当我尝试访问 myapp 时,我收到此错误无法在浏览器控制台中获取 / myapp /和 404
我可以得到一个正常的 nodejs 应用程序运行没有表达在 app.js 的内容
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
server.listen(8000);
console.log("Server running at http://127.0.0.1:8000/");
但无法让 Express 应用程序运行
您需要在应用程序中添加路由:
app.get('/myapp', function(req, res){...});
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(29条)