我正在使用Node.js和Express开发一个应用程序。
我想将其导出为使用node-webkit的包。
如何启动服务器并运行应用程序?
我正在使用Node.js和Express开发一个应用程序。
我想将其导出为使用node-webkit的包。
如何启动服务器并运行应用程序?
npm install express
npm install express-handlebars
{
"name": "app",
"main": "resources/index.html"
}
步骤5:
前往资源文件夹并创建一个名为index.html的文件。在里面复制以下代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<!--______________________________________________________BEGIN APP-->
<body>
<script>
</script>
<script>
var express = require('express');
var app = express();
var expressHbs = require('express-handlebars');
app.engine('hbs', expressHbs({
extname: 'hbs'
}));
app.set('view engine', 'hbs');
app.get("/", function(req, res) {
res.render("index", {
item: "weeeeeeeee"
})
})
app.listen("3000", function(err) {
if (err) {
console.log("server is not working");
} else {
console.log("Server is working on 3000");
}
})
window.location.href = 'http://localhost:3000';
</script>
</body>
<!--______________________________________________________END APP-->
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<!--______________________________________________________BEGIN APP-->
<body>
<p>Oink</p>
{{item}}
</body>
<!--______________________________________________________END APP-->
</html>
最后一步。
在app-parent文件夹中点击名为nw.exe的文件。您的应用程序应该启动。
完成
Node-Webkit(意思是nodeJS+chromium框架),因此您可以直接在应用程序中运行服务器代码(Express.js等),只需安装expressJS,然后直接调用客户端代码即可。