Sign Up

Talk Programming , Career, Mental Health, Talk Personal Finance ❤️‍ Post a query and receive responses ✅

Have an account? Sign In


Have an account? Sign In Now

Sign In

Post a query and receive responses. Ask anything, Ask Mitra ❤️‍

Sign Up Here


Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.


Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.


Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Ask Mitra

Ask Mitra Logo Ask Mitra Logo

Ask Mitra Navigation

  • Home
  • About Us
  • Find Jobs
  • Blogs
    • Add New Blog !
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Ask a Question
  • Home
  • All Categories
  • Find Jobs
  • Points and Swags
    • Badges and Points
    • Ask Mitra Swags
  • Blog
    • Add New Blog !
  • FAQs
  • Community Members 💓
  • About Us
  • Contact Us
Home| Questions|Q 84183
Next
In Process
GrgBirajan
GrgBirajanBeginner
Asked: October 25, 20222022-10-25T14:23:28+05:45 2022-10-25T14:23:28+05:45In: —Node Js

Node.js localhost server keeps loading….

Hi, I’m self learning Node.js recently and now i’m stuck.

I was building small weather app project using node.js and everytime i run res.write(readTimeData), localhost keeps loading infinitely. All the files (index.js, script.js and style.css) keeps pending.

Although i was getting right output of realTimeData in console but couldn’t get in browser.

I did found one solution, i.e. i have write all css and javascript in index.html file. But if i include external css and javascript then again it keeps loading. So, how can i get proper output with external files?

Any help is appreciated and please help me point out my mistakes.

Thank you!!!

  • 0
  • 2 2 Answers
  • 55 Views
  • 0 Followers
  • 0
Share
  • Facebook

    Related Questions

    • Any alternate of heroku?
    • Does anyone have any idea, how to query in this document so that i can find all the documents having ...
    • I have encountered this error while deploying my mern project on Heroku? does anyone have any idea.. Netowork access 0.0.0.0/0 ...
    • Token not sending to the Request Header
    • How to make 'like' system ?

    You must login to add an answer.


    Forgot Password?

    Need An Account, Sign Up Here

    2 Answers

    • Voted
    • Oldest
    • Recent
    • Random
    1. Cookie Beginner
      2022-10-26T07:57:19+05:45Added an answer on October 26, 2022 at 7:57 am

      Ig this will help you out

      https://stackoverflow.com/a/3944751/3018595

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. BidhanN
      2022-12-27T21:26:20+05:45Added an answer on December 27, 2022 at 9:26 pm

      const express = require(‘express’);
      const https = require(‘https’);
      const bodyParser = require(‘body-parser’);
      const {parse} = require(‘path’);

      const app = express();

      app.use(bodyParser.urlencoded({extended: true}));

      app.get(‘/’, (req, res) => {
      res.sendFile(__dirname + ‘/index.html’);
      });

      app.post(‘/’, (req, res) => {
      const city = req.body.cityName;
      const url = ‘https://api.openweathermap.org/data/2.5/weather?q=’ + city + ‘&appid=”API KEY”&units=metric’;
      https.get(url, (response) => {
      console.log(‘Code: ‘, response.statusCode);
      response.on(‘data’, (data) => {
      const weatherData = JSON.parse(data);
      const temp = weatherData.main.temp;
      const description = weatherData.weather[0].description;
      const icon = weatherData.weather[0].icon;
      const imgUrl = ‘<img src = http://openweathermap.org/img/wn/‘ + icon + ‘@2x.png>’;

      res.write(‘<p>The whether is currently ‘ + description + ‘ <p>’);
      res.write(‘<h1>The temperature in ‘ + city + ‘ is ‘ + temp + ‘ degree celcius</h1>’);
      res.write(imgUrl);
      res.send();
      });
      });
      });

      app.listen(3000, () => {
      console.log(‘The server is running at port 3000’);
      });

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Sidebar

    Ask A Question

    Your Favourite Topics

    • Announcements
    • Blockchain
    • Books

        • —Non Tech Books
        • —technical books
    • Business and Entrepreneurship
    • Careers
    • College
    • Content and Blog
    • CyberSecurity
    • Design and Arts
    • Devices and Gadgets
    • Digital Marketing
    • Entertainment

        • —Movies-Series-TV
        • —Music
        • —Sports
    • Events
    • For Admins only.
    • Health

        • —Fitness
    • Money

        • —Personal Finance
        • —Stock Market
    • Operating System

        • —linux
        • —windows
    • Other
    • Paid Internship
    • Programming

        • —AI/ML
        • —APIs
        • —C & C#
        • —Django
        • —Flutter
        • —Go
        • —HTML&CSS
        • —Java
        • —JavaScript
        • —Mobile Apps Development
        • —Node Js
        • —NoSQL
        • —Php
        • —Python
        • —React JS
        • —SQL

    Stats

    • Questions 1k
    • Answers 10k
    • Best Answers 391
    • Users 2k

    Top 6 Members This Month

    Vicky

    Vicky

    • 0 Questions
    • 78 Points
    Sensei
    puppet

    puppet

    • 0 Questions
    • 23 Points
    Beginner
    wtfixair

    wtfixair

    • 0 Questions
    • 22 Points
    Beginner
    Dhanmaya

    Dhanmaya

    • 0 Questions
    • 20 Points
    Beginner
    Riyesh

    Riyesh

    • 0 Questions
    • 20 Points
    Beginner
    pranitkarki

    pranitkarki

    • 0 Questions
    • 20 Points
    Beginner

    Trending Tags

    askmitra blockchain c++ career coding College cybersecurity Django Flutter help javascript laptop laravel linux poll Programming python question react web web development wordpress
    • Popular
    • Answers
    • Rounak Agrawal

      Ask Mitra Udemy Courses Giveaway

      • 76 Answers
    • Subedi Bibek

      The Complete JavaScript Course 2022: From Zero to Expert! Udemy ...

      • 73 Answers
    • Subedi Bibek

      Mega Giveaway at askmitra.com 🔥

      • 69 Answers
    • bishwaKiran
      bishwaKiran added an answer Try getting into githubs student program, use your university/collage/school ID… January 30, 2023 at 7:44 pm
    • Sandeep Poudel
      Sandeep Poudel added an answer SOLVED: It was due to unfinished SSL certificate installation January 27, 2023 at 7:11 pm
    • Aashutosh_k
      Aashutosh_k added an answer Software piracy protection system Fingerprint voting system Stock price prediction… January 26, 2023 at 7:37 pm

    Related Questions

    • Any alternate of heroku?

      • 3 Answers
    • Does anyone have any idea, how to query in this ...

      • 1 Answer
    • I have encountered this error while deploying my mern project ...

      • 2 Answers
    • Token not sending to the Request Header

      • 0 Answers
    • How to make 'like' system ?

      • 3 Answers

    Explore

    • Home
    • Trending Category
      • Programming
      • Web Development
      • —Mobile Apps Development
      • —Stock Market
      • Business and Entrepreneurship
      • Blockchain
      • College
      • —Personal Finance
      • —HTML&CSS
      • —JavaScript
      • —Python
      • —React JS
      • —Node Js
      • —C & C#
      • Content and Blog
      • Careers
    • All Categories
      • Go to All Categories
      • Health
      • —Go
      • —Flutter
      • Digital Marketing
      • —APIs
      • Devices and Gadgets
    • Find Job and Internships
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • All Blogs
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • Questions
      • Un Answered
      • New Questions
      • Most Seen Questions
      • Most Answered
      • Trending Questions
    • Tags

    Footer

    Ask Mitra

    Ask Mitra

    Ask Mitra is a social question and answer engine that will assist you in forming a community and connecting with others. Talk about programming, your career, your mental health, and your personal finances. ❤️‍ Post a query and receive responses ✅

    Quick Navigation

    • Ask a Question
    • Home
    • All Categories
    • Find Jobs
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • Blog
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • About Us
    • Contact Us

    Legal Stuff

    • Terms of use and policy