我才刚刚开始研究Zeit的PKG,我正在尝试将Express服务器转换为可部署的程序包。该应用程序可以运行并且具有大多数功能,但是它不能提供客户端文件(css,js和图像),并且在尝试将fs.writeFile转换为我拥有的config.json文件时显示错误。
fs.writeFile(
$ {__ dirname} /data/fxConfig.json , data, (err) => {
还有我的package.json
{
"name": "dicon_server",
"version": "1.0.0",
"description": "HTTP API",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [
"http",
"server",
"api"
],
"author": "Mitchell Day",
"license": "ISC",
"pkg": {
"scripts": "scripts/*.js",
"assets": "data/**/*"
},
"bin": "index.js",
"dependencies": {
"child-process": "^1.0.2",
"child_process": "^1.0.2",
"directory-tree": "^2.1.0",
"express": "^4.16.4",
"local-network-scanner": "^0.2.0",
"md5-hex": "^2.0.0",
"net": "^1.0.2",
"node-gyp": "^3.8.0",
"play": "^0.5.0",
"request": "^2.88.0",
"serialport": "^6.2.1",
"socket.io": "^2.1.1",
"sqlite3": "^4.0.2"
},
"devDependencies": {}
}
主目录下有一个数据文件夹,其中包含所有客户端数据,而主目录下有一个脚本文件夹,其中包含我自己的index.js所需的脚本。
还具有此静态资产代码,用于提供客户数据
app.use(express.static('data'))
app.use('/static', express.static('node_modules'))
app.use(express.static(`${__dirname}/data`))
但是我仍然无法使fs.writeFile工作。