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 8945883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:21:53+00:00 2026-06-15T12:21:53+00:00

I am trying to add some variables from my app.js file into the file

  • 0

I am trying to add some variables from my app.js file into the file compiled by connect-assets.

I have a file called file.ejs

<%- js('code.js') %>
<input type="text" value="Doe">

In app.js I have:

 app.locals.url = 'http://123.123.123.123'

In code.js I would like to add some production/development variables depending on the system (<%- url %>). When I try to do this, the variable added is rejected, becuase connect-assets is compiling them as tags. What is the proper way to pass in variables into code.js?

  • 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-15T12:21:54+00:00Added an answer on June 15, 2026 at 12:21 pm

    code.js is a treated as a static file, so you cannot pass variables into it from an EJS template. Generally in cases like this where you are passing in data based on an environment, you would set some kind of global config variable that you could read inside code.js.

    Rather than set app.locals globally for values like this, you could have a set of settings somewhere for your different environments. Say somewhere in your code you have this:

    var environments = {
      production: {
        url: 'http://1.1.1.1'
      },
      development: {
        url: 'http://2.2.2.2'
      }
    };
    

    When you render your main page template, or somewhere that will be easily accessible, you can pass in the proper settings whatever environment you are in. When rendering the template, you pass the settings. html = new EJS(...).render({settings: settings['production']});

    <html>
      <head>
        <script type="text/javascript">
          var AppSettings = <%= JSON.stringify(settings); %>;
        </script>
    
        ...
    

    And then inside of your code.js file, you can read AppSettings.url directly.

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

Sidebar

Related Questions

I have been trying to add variables from a dropdown into an array using
I'm trying to add some client-side list grouping functionality into my Rails app. It's
Im trying to add some short file names to a Wise installer to fix
I was trying to add some non-production test code by creating a 3rd partial
I'm trying to add some navigation controller in my app, it's sth likes: in
I'm trying to add some accessibility for screen readers into a Flash application, and
I am trying to implement UISearch bar but I have some problems. When app
I am trying to implode some variables and insert them into a MySql database,
I have the following bit of code. I'm trying to dynamically add drop-down options
I'm trying to add some sort of a superglobal in my app. It will

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.