За последние 24 часа нас посетили 22056 программистов и 1114 роботов. Сейчас ищут 710 программистов ...

node js

Тема в разделе "JavaScript и AJAX", создана пользователем riaron, 23 июн 2020.

  1. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    учусь node.js-у возникли две ошибки для 2х вьюх
    вот вьюхи:
    1-ая ошибка
    (node:4980) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
    undefined:1
    <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    ^

    SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Request._callback (C:\OSPanel\domains\mysite5.local\labs\lab-5.js:19:16)
    at Request.self.callback (C:\OSPanel\domains\mysite5.local\node_modules\request\request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.<anonymous> (C:\OSPanel\domains\mysite5.local\node_modules\request\request.js:1154:10)
    at Request.emit (events.js:315:20)
    at IncomingMessage.<anonymous> (C:\OSPanel\domains\mysite5.local\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (events.js:421:28)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1201:12)
    вот вьюха
    google-search.ejs:
    Код (Javascript):
    1. <h3>Результат поиска по <%= keyword %></h3>
    2. <dl>
    3.   <% feeds.entries.forEach(function(feed){ %>
    4.     <dt><a href="<%- feed.link%>"><%- feed.title %></a></dt>
    5.     <dd><%- feed.contentSnippet %></dd>
    6.   <% }); %>
    7. </dl>
    2-я вьюха
    ошибка:
    (node:1616) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
    undefined:1
    <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    ^

    SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Request._callback (C:\OSPanel\domains\mysite5.local\labs\lab-5.js:53:17)
    at Request.self.callback (C:\OSPanel\domains\mysite5.local\node_modules\request\request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.<anonymous> (C:\OSPanel\domains\mysite5.local\node_modules\request\request.js:1154:10)
    at Request.emit (events.js:315:20)
    at IncomingMessage.<anonymous> (C:\OSPanel\domains\mysite5.local\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (events.js:421:28)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1201:12)
    2-я вьюха:yandex-views.ejs
    Код (Javascript):
    1. <h3>
    2. <%= count%> posl nov<%= category%>
    3. </h3>
    4. <dl>
    5. <%  news.entries.forEach(function(item){%>
    6.   <dt><a href="<%- item.link%>"><%- item.title%></a></dt>
    7.   <dd><%- item.contentSnippet%></dd>
    8. <%});%>
    9. </dl>
    вот сервер
    lab-5.js
    Код (Javascript):
    1. var url=require('url');
    2. var request=require('request');
    3. var express=require('express');
    4. var ejs=require('ejs');
    5. var   MY_IP='109.252.53.254';
    6. var app=express();
    7. app.listen(8080);
    8. app.set('views',__dirname);
    9. app.get('/google/feeds/for/:search', function(req, response){
    10. var search=req.params.search;
    11. var options={
    12. protocol: 'http',
    13. host: 'ajax.googleapis.com',
    14. pathname: '/ajax/servises/feed/find',
    15. query:{v:'1.0', userip: MY_IP, q:search}
    16. };
    17. var searchURL=url.format(options);
    18. request(searchURL, function(err, res, body){
    19. var feeds=JSON.parse(body);
    20. response.render('google-search.ejs', {feeds: feeds.responseData,keyword: search});
    21. });
    22. });
    23. var categories={
    24.     'auto':"Автомобили",
    25.      'world':"В мире",
    26.     'internet':"Интернет",
    27.     'sport':"Спорт",
    28.     'culture':"Культура",
    29.     'movies':"Кино",
    30.     'politics':'Политика',
    31.     'index':"Главные новости"
    32. };
    33. app.get('/yandex/:cnt/news/for/:search', function(req,response){
    34.     var search=req.params.search;
    35.     if(!(search in categories))
    36.         search='index';
    37.     var name=categories[search];
    38.     var cnt=req.params.ctn;
    39.     var options={
    40.         protocol:'http',
    41.             host:'ajax.googleapis.com',
    42.             pathname:'/ajax/services/feed/joad',
    43.         query:    {
    44.                     c:'1.0',
    45.                     num:cnt,
    46.                     userip:MY_IP,
    47.                     q: 'http://news.yandex.ru'+search+".rss"
    48.         }
    49.  
    50.     };
    51.     var searchURL=url.format(options);
    52.     request(searchURL, function(err, res, body){
    53.         var news=JSON.parse(body);
    54.         response.render('yandex-news.ejs', {news: news.responseData.feed,category: search,count: cnt});
    55.     });
    56. });
    подскажите где ошибка