小编kov*_*gel的帖子

npm"无法解析json"

当我尝试使用npm安装express时,我总是会收到以下错误:

Failed to parse json
No data, empty input at 1:1
File: /root/.npm/inherits/2.0.1/package/package.json
Failed to parse package.json data.
package.json must be actual JSON, not just JavaScript.

This is not a bug in npm.
Tell the package author to fix their package.json file. JSON.parse
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

 sudo npm install -g express
Run Code Online (Sandbox Code Playgroud)

操作系统是Ubuntu 12.04(精确)armhf

ubuntu node.js npm

40
推荐指数
3
解决办法
5万
查看次数

如何使用Express/Socket.io在Node.js上使用HTTPS

我试图用https运行我的节点服务器.我正在使用express和socket.io.

这是我的https代码:

var httpsPort = 443;
var privateKey = fs.readFileSync(mykeypath');
var certificate = fs.readFileSync(mycertificatepath');
var credentials = {key: privateKey, cert: certificate};
var https = require('https').Server(credentials,app);
var io = require('socket.io')(https);

https.listen(httpsPort, function(){
logger.info('listening on *:' + httpsPort);
});


app.get('/initGame', function (req,res){

var slots = require('./slots.json', 'utf8');
var userObject = {
    address : req.connection.remoteAddress,
    userAgent : req.headers['user-agent']
};
db.getPlayedGames(userObject,function(playedGames){
    logger.debug(playedGames);
    if(typeof playedGames == 'undefined' ){
        playedGames=0;
    }else{
        playedGames = playedGames.games_played;
    }
    var spinsLeft = 10-playedGames;
    res.json({
        spinsLeft: spinsLeft,
        slots: slots
    });
  }); …
Run Code Online (Sandbox Code Playgroud)

https node.js express socket.io

26
推荐指数
1
解决办法
5万
查看次数

标签 统计

node.js ×2

express ×1

https ×1

npm ×1

socket.io ×1

ubuntu ×1