作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 IBM Bluemix 为学校项目创建 Web 服务。
我设置了本地主机来运行我的代码,但是当我在 Windows 10 命令提示符中键入“npm start”时,我遇到了“assert.AssertionError”。
当我尝试运行我的代码时遇到了assert.AssertionError。
是什么导致了这个错误以及如何消除它?
这是我的 .js 文件:
/*eslint-env node*/
//------------------------------------------------------------------------------
// node.js starter application for Bluemix
//------------------------------------------------------------------------------
//"Ask" express
var express = require(express);
// HTTP request - duas alternativas
var http = require('http');
var request = require('request');
// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');
// create a new express server
var app = express();
// serve the files out of ./public as our main files
app.use(express.static(__dirname + '/public'));
// get the app environment from Cloud Foundry
var appEnv = cfenv.getAppEnv();
//chama o express, que abre o servidor
var express = require('express');
// start server on the specified port and binding host
app.listen(appEnv.port, '0.0.0.0', function() {
// print a message when the server starts listening
console.log("server starting on " + appEnv.url);
});
app.get('/home1', function(res){
http.get('http://developers.agenciaideias.com.br/cotacoes/json', function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var json = JSON.parse(body);
});
var json = JSON.parse(res);
var cotacao = json["bovespa"]["cotacao"];
console.log("A sua cotação é "+cotacao);
});
});
这是我执行“npm start”时收到的错误屏幕的打印。请注意,“C:xxxxx”路径是包含我的 .js 文件的目录。
最佳答案
您的nodejs应用程序找不到“express”模块,因此您面临这个问题。
更改线路
var express = require(express);
在
var express = require('express');
或者直接删除该行,因为它是重复的。您已经需要该模块
//chama o express, que abre o servidor
var express = require('express');
关于javascript - NodeJS断言.AssertionError : How do I kill it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34055681/
我是一名优秀的程序员,十分优秀!