Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Wont output console.log to the terminal

I'm trying to learn the basics of node.js and am following a tutorial on youtube, but my code won't output to the terminal when I go to localhost:3000.

Here is my code:

app.js

var express = require("express");
var path = require("path");

var routes = require("./routes");

var app = express();


app.set("port", process.env.PORT || 3000);

app.use(routes);

app.listen(app.get("port"),function(){
    console.log("Server started on port " + app.get("port"));
});

routes.js

var express = require("express");

var router = express.Router();

router.get("/", function(req,res){
    console.log("Hello I'm on the start page here");
    //res.render("index");
});

module.exports = router;

Can someone please explain why?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In app.js try this:-

  const express = require("express"),
        path = require("path"),
        routes = require("./routes"),
        app = express(),
        port = process.env.PORT || 3000,
        host = process.env.HOST || 127.0.0.1;
  app.use(routes);
  app.listen(port, host, (err) => {
    if(err) console.log(`Some error has occured due to: ${err}`);
    console.log(`The server has started on http://${host}:${port}/`);
  });

For routes.js:-

const router = require("express").Router();
router.get("/", (req, res) => {
  console.log("The home page of this web app.");
  res.status(200).send("Home");
});

I am not 100% sure that this will work.

Thank you!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!