Home
Support Forums

How to deploy a site with EJS files?

Hey,

I have this site which includes ejs files (GitHub - Technaut/monk_checker)

It runs fine using npm start on my local machine; i just cant figure out how to deploy on netlify

I tried this but it didnt work I am unable to deploy a nodejs/ejs application on netlify - #4 by talves

https://app.netlify.com/sites/sleepy-goldwasser-73be5f/deploys/617fe92909aedc00086037bb

Any help as I dont really have a clue on how to fix?

1 Like

maybe @talves has some more ideas?

1 Like

Hi @bullnaut,

I have some pressing items to take care of this morning, but I’ll take a look at yours later this afternoon if I can free up the time.

Thanks for the ping @perry, I’ll definitely be interested in what the issue is here. :grin:

-Tony

1 Like

I’m running your repo local and want to get you what I found along the way in building your repo.

#1 you are not git ignoring the public/apebase in your repo, so you would not be bringing down the most recent during the build process, but you might expect that it is a manual process (warning)

#2 The build script build.js is not spelled correctly so your index.html (node.html) isn’t built on the command run.

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '/home/talves/git/talves/others/technaut-monk-checker/build.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

#3 When I fixed the command file build.js, I get the following error

ReferenceError: /home/talves/git/talves/others/technaut-monk-checker/views/index.ejs:135
    133| <div class='flex'>
    134|   <div class='editor'>
 >> 135|     <div id='editor'><%=query%></div>
    136|     <button id='query'>Filter</button>
    137|   </div>
    138|   <div class='container'>

query is not defined
    at eval (eval at compile (/home/talves/git/talves/others/technaut-monk-checker/node_modules/ejs/lib/ejs.js:662:12), <anonymous>:12:25)
    at index (/home/talves/git/talves/others/technaut-monk-checker/node_modules/ejs/lib/ejs.js:692:17)
    at tryHandleCache (/home/talves/git/talves/others/technaut-monk-checker/node_modules/ejs/lib/ejs.js:272:36)
    at Object.exports.renderFile (/home/talves/git/talves/others/technaut-monk-checker/node_modules/ejs/lib/ejs.js:489:10)
    at /home/talves/git/talves/others/technaut-monk-checker/build.js:11:9
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3) {
  path: '/home/talves/git/talves/others/technaut-monk-checker/views/index.ejs'
}

#4 This is going to be the rub issue. You are running the index.js script locally for development feeding up the files with the paths resolved. This is not going to work in this case, because you need to be creating static content (pure html) pages with a working index.html. Those files then need to have an api proxy path to go get the data you are using at the get pages. This would usually happen with a netlify function or some other api service where the data can be queried and returned to page.

I think starting there and fixing those issues, might get you farther, then you can come back and let us know where you are from there. Remember, Netlify doesn’t allow you to create an app server in your published files location. Only static content is pushed out to the CDN for the site. Hope that’s clear and helps you out.

NOTE: Excuse me if the data is being fetched by the static paths. If that is the case, you wouldn’t need to use the functions. I didn’t get that far in the debugging, but wanted you to know.

Tony