0

UPDATED

I have researched this a lot further. The web application is using the node-db-migrate package. There is a migration folder with two migrations (with table creations). Since I just git cloned it down I am sure I need to run this and I do have node-db-migrate installed on my machine when I hit npm-list.

I head into this folder and hit db-migrate-up and tried db-migrate-up [filename] but I am getting -bash: db: command not found.

I am using this with the node-postgres package. It should be loading the database.json file according to the node-db-migrate file.

Hi in my data.coffee here is line 1 to 17 as requested, according to the command line it could be the data part that is having problem.

uuid = require 'node-uuid'
fs = require 'fs'
_ = require 'underscore'
moment = require 'moment-timezone'
apis = require '../logic/apis'
q = require 'q'

data = (_.chain fs.readdirSync "data")
    .map (filename) ->
        "data/" + filename
    .map (f) ->
        fs.readFileSync f, "utf8"
    .map (p) ->
        JSON.parse p
    .sortBy (json) ->
        -json.intlFormatDateTime
    .value()

Hi I come from a ruby/rails/sinatra background. I just inherited a javascript web app and I will be rewriting the back end.

I am just trying to start the app locally for now

I did

coffee app.coffee -n 

but I am getting the error below.

Error: ENOENT, no such file or directory 'data'
  at Object.fs.readdirSync (fs.js:654:18)
  at Object.<anonymous> (/Users/judyngai/Desktop/twiage/twiagemed/nodejs/routes/data.coffee:8:17, <js>:16:22)
  at Object.<anonymous> (/Users/judyngai/Desktop/twiage/twiagemed/nodejs/routes/data.coffee:1:1, <js>:226:4)
  at Module._compile (module.js:456:26)
  at Object.loadFile (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:182:19)
  at Module.load (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:211:36)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Object.<anonymous> (/Users/judyngai/Desktop/twiage/twiagemed/nodejs/app.coffee:3:8, <js>:8:10)
  at Object.<anonymous> (/Users/judyngai/Desktop/twiage/twiagemed/nodejs/app.coffee:1:1, <js>:76:4)
  at Module._compile (module.js:456:26)

In the app.coffee file there is these three lines of code

express = require 'express'
routes = require './routes'
data = require './routes/data'

I have installed all the dependencies within the package.json file but there is a database.json file with this line attached

{  "dev": "postgres://twiage_db_user:twiage_db_password@localhost/twiage_db" }

how do I create this database? normally in rails its a rake db:create. I feel like this can solve the problem.

2
  • what's in your data.coffee? Commented Dec 25, 2013 at 21:38
  • @AndreySidorov Hi Andrey I just posted it. Commented Dec 25, 2013 at 21:46

1 Answer 1

1

It tries to read "data" directory which is missing. Does cwd + ./data/ exist? Also, it's common to use path relative to script with __dirname variable:

dataDir = __dirname + "/data"
data = (_.chain fs.readdirSync dataDir)
    .map (filename) ->
        dataDir + "/" + filename
    .map (f) ->
        fs.readFileSync f, "utf8"
    .map (p) ->
        JSON.parse p
    .sortBy (json) ->
        -json.intlFormatDateTime
    .value()
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't have a data directory, created one and the error went away also I switched to your way of specifying the directory path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.