SailsJS and Forever doesn't work with CoffeeScript - node.js

I have a SailsJS app, with much of it written in CoffeeScript.
When running it in Prod mode using "sails lift" all is good.
Running it with forever doesn't work. If I examine the logs, the problem seems to be with node running app.js
/var/www/obelix/api/models/Catalogue.coffee:2
attributes:
^
SyntaxError: Unexpected token :
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /var/www/obelix/node_modules/sails/node_modules/include-all/index.js:96:53
at Array.forEach (native)
at requireAll (/var/www/obelix/node_modules/sails/node_modules/include->all/index.js:40:9)
at buildDictionary >(/var/www/obelix/node_modules/sails/lib/moduleloader/index.js:60:36)
Is it possible to get a sails+coffeescript app to run using node/forever?

The problem is that coffee-script support doesn't work unless you're using sails lift.
Try requiring coffee-script in your app.js file:
// Start sails and pass it command line arguments
require('coffee-script');
require('sails').lift(require('optimist').argv);
Then npm install coffee-script --save

Related

React-native start

Following the instructions for initial setup I stucked when found a red screen with:
ReferenceError: Can't find variable: __fbBatchedBridge (line 1 in the
generated bundle)
After reloading it changes and becomes:
Unable to download JS bundle
Than I found an advice for typing react-native start into the console. The result:
react-native start
/local/react_native/android_program1/node_modules/react-native/local-cli/cli.js:74 const setupEnvScript = /^win/.test(process.platform) ^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/local/react_native/android_program1/node_modules/react-native/node_modules/babel-core/node_modules/babel-register/lib/node.js:142:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/local/react_native/android_program1/node_modules/react-native/cli.js:15:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
I'm using:
RHEL 7, npm 1.3.6, nodejs 0.10.36 and react-native 0.19.
How can I make it work?
install node js
open command promt.
type: react-native init projectName
this command will automatically download all the required dependancies for project.
open the directory from cmd using cd projectname
react-native run-android
if u face the error like : make sure you have npm install.
then just exicute this command
npm install --save
your project will run successfully.
hope it work for you..

Getting koa to work (nodejs web framework)

I am running Deepin and trying to get koa to work. There is little documentation on the subject.
I did the following as stated on koajs.com:
$ npm install -g n
$ n 0.11
$ node --harmony my-koa-app.js
I recieve the error:
➜test-koa-app$ sudo node --harmony test-koa-app.js
module.js:338
throw err;
^
Error: Cannot find module 'koa'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/karl/nodejs/test-koa-app/test-koa-app.js:1:73)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
As Mike Kamermans mentioned in the question comments, to use a module in a node application, it must first be installed in the project directory.
To install it, run npm install koa in a terminal in your project folder.
If you've run npm init and setup a package.json file in your project, you can add the --save flag and save a record of the dependency with npm install --save koa.
Version 2 of koa now out. Go here:
https://github.com/koajs/koa

Error: cannot find module './lib/middleware'

I am attempting to run the demo for the mobwrite node.js package. First I installed the mobwrite package (npm install mobwrite) and then entered the following command:
node -e "require('mobwrite').quickserve()"
A demo server should start, but the following error is thrown:
module.js:340
throw err;
^
Error: Cannot find module './lib/middleware'
at Function.Module._resolveFilename (module.js:388:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (PATH_TO_MODULES\mobwrite.js:2:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at [eval]:1:1
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compie (module.js:456:26)
at evalScript (node.js:532:25)
at startup (node.js:80:7)
at node.js:901:3
This originates from the mobwrite.js file, in which the package needs to include a middleware file (middleware.coffee) which is stored in a lib folder:
require("coffee-script")
middleware = require("./lib/middleware")
module.exports = middleware
I have looked at the answers to similar posts on SO, but nothing has solved my problem so far. How can I overcome this error?
You could try manually compiling the coffeescript files to javascript: npm install -g coffee-script && coffee -c node_modules/mobwrite/lib/middleware.coffee && coffee -c node_modules/mobwrite/lib/daemon.coffee. Then retry your command.

not able to run sails.js app using forever / pm2 in amazon ec2 / digitalocean ubuntu

I have installed sails.js (v0.9.16) globally in amazon-ec2 / digitalocean ubuntu..
sudo npm -g install sails
created a test project..
sails new sailstest
then lifted the server.. it works fine..
cd sailstest
sails lift
i can see sails app homepage on
http://<domain>:1337/
But when i am trying run it using pm2 from app directory,
pm2 start app.js
i am getting following error..
Error: Cannot find module 'sails'
at Function.Module._resolveFilename (module.js:331:15)
at Function.Module._load (module.js:273:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object.<anonymous> (/var/www/authenticator/sailstest/app.js:2:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (/usr/lib/node_modules/pm2/node_modules/coffee-script/lib/coffee-script/r$
at Function.Module._load (module.js:305:12)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at /usr/lib/node_modules/pm2/lib/ProcessContainer.js:151:5
at WriteStream.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainer.js:104:9)
at WriteStream.EventEmitter.emit (events.js:107:17)
at WriteStream.<anonymous> (fs.js:1668:10)
at Object.oncomplete (fs.js:97:15)
I tried running using forever as well..
forever start app.js
getting below error..
module.js:333
throw err;
^
Error: Cannot find module 'sails'
at Function.Module._resolveFilename (module.js:331:15)
at Function.Module._load (module.js:273:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object.<anonymous> (/var/www/authenticator/sailstest/app.js:2:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Function.Module.runMain (module.js:490:10)
error: Forever detected script exited with code: 1
/usr/lib/node_modules/forever/node_modules/forever-monitor/node_modules/broadway/node_modu$
throw arguments[1]; // Unhandled 'error' event
^
Error: Cannot stop process that is not running.
at /usr/lib/node_modules/forever/node_modules/forever-monitor/lib/forever-monitor/moni$
at process._tickCallback (node.js:343:11)
Any idea what is wrong?
I have upgraded to latest version of sails.js.. Now its working fine with forever and pm2...
npm -g update sails
Now sailsjs version 0.10.0-rc7 works fine with forever & pm2..

Node js Express module.js:340

I'm having trouble running my app in node. When I first got the module.js:340 error, I used a sudo npm install express -g, and it looked like Express is installed but when I run my app again I get this error.
module.js:340
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/mac/Downloads/node-FED-master/app.js:6:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
users-Mac-Pro:node-FED-master mac$
You've installed Express globally (with -g), which gives you access to the express command line tool, but Node programs can't access the global module. You need to install Express locally by doing npm install express in your project directory.
If the project has a package.json, a simple npm install in the project directory will install all necessary dependencies in it's correct versions.

Resources