Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

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

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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:17:35+00:00 2026-06-15T13:17:35+00:00

I’m building a site that has somewhat reddit-like functionality. I want user-submitted content to

  • 0

I’m building a site that has somewhat reddit-like functionality. I want user-submitted content to get its own page. Each submission is assigned a 5 character ID that I want to be in the URL for that page.

I’ve got this function in the router file which renders a page called titles:

exports.titles = function(req, res){
i = 0
read(function(post){
    url = post[i].URL;
    res.render('titles', {title: post[i].title, url: post[i].URL});
});

};

It is served by this statement in app.js:

app.get('/titles', home.titles); //home.js is the router file

The titles page has a link with the text post.title and the URL post.URL. When a user clicks on the link (e.g. domain.com/12345) they should be taken to a page called content with the content post.body.

How do I a)pass the URL back to my app.js file to include in an app.get, b) include the app.get function in this router file, or c) solve this in any other way?

Edit: I do have an object ‘titles’ that is a mongodb collection, but it is in a different module. No reason I can’t add it to the router though.

Edit: I tried adding this to app.js to see if it would work:

app.get('/:id', function(req, res){
  return titles.findOne({ id: req.params.id }, function (err, post) {
    if (err) throw(err); 

    return res.render('content', {title: post.title, content: post.body});
   });
});

Edit: I got it to work. All I did was format the title so that it would look like domain.com/titles/12345 and change app.get(‘/:id’, to app.get(‘/titles/:id, …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:17:36+00:00Added an answer on June 15, 2026 at 1:17 pm

    If I get you right I would do that the other way around.

    Short version

    1. I would get the id from the URL
    2. Then I would pull from the database the data associated with this id
    3. And use this data to build the final page.

    You don’t need to create a new route for each URL. An URL can contain some variable (here the id) and Express can parse the URL in order to get this variable. Then from this id you can get the data needed to build the proper page.

    Long version

    I assuming someone type in this URL: http://domain.com/1234.
    I also assume that you have a variable titles which is a MongoDB Collection.

    You can have a route defined like this:

    app.get('/:id', function(req, res) {
      // Then you can use the value of the id with req.params.id
      // So you use it to get the data from your database:
      return titles.findOne({ id: req.params.id }, function (err, post) {
        if (err) { throw(err); }
    
        return res.render('titles', {title: post.title, url: post.URL /*, other data you need... */});
      });
    });
    

    Edit

    I made some changes according to the last comments…

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.