grunt not launching my nodejs server - javascript

I'm trying nodejs to build a webapp and I'm trying to work with grunt
this is the content of my current directory
C:\data\nodeprojects>dir
Répertoire de C:\data\nodeprojects
08/15/2014 01:48 PM <DIR> .
08/15/2014 01:48 PM <DIR> ..
08/15/2014 05:24 PM 238 gruntfile.js
08/15/2014 01:44 PM <DIR> node_modules
08/15/2014 01:45 PM 316 package.json
08/15/2014 01:08 PM 54 readme
08/15/2014 02:34 PM 526 server.js
4 fichier(s) 1,134 octets
3 Rép(s) 118,564,114,432 octets libres
and when I launch my nodejs server I get the following :
C:\data\nodeprojects>node server.js
Server is listening
_
after that I can go to my web browser, access to my localhost, and see a pretty nice hello world page.
But my problem is the following :
This is the content of my gruntfile.js :
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
nodemon : {
dev : {
sript: 'server.js'
}
}
});
grunt.loadNpmTasks('grunt-nodemon');
}
when I launch grunt nodemon ths is what I see :
C:\data\nodeprojects\bubblepeople>grunt nodemon
Running "nodemon:dev" (nodemon) task
_
I guess grunt is actually running, but I think it didn't launch my server.js script, I should see my server.js output (Server is listening). And, of course when I go to my browser, I can't access to my local website anymore.
I know my grunfile seems a bit short, but I thougth this was enought to run my script with nodemon using grunt.
Do someone know what I am doing wrong here ?
thx

Related

Watching for file changes when developing lambda docker image

I have a TypeScript function defined at src/index.ts for AWS Lambda below. For the purpose of this question, it simply sends a JSON body with a "hello world" statement. While running the docker container locally and making a file change, the lambda return value should change accordingly.
import { Context, APIGatewayProxyResult, APIGatewayEvent } from "aws-lambda";
export const handler = async (
event: APIGatewayEvent,
context: Context
): Promise<APIGatewayProxyResult> => {
return {
statusCode: 200,
headers: {
"content-type": "application/json",
},
body: JSON.stringify({ text: "hello world" })
};
};
My yarn develop command is equal to the following shell command:
esbuild src/index.ts --watch --bundle --minify --sourcemap --platform=node --target=es2020 --outfile=build/index.js
Paired with yarn develop, I use the following Dockerfile.dev to set up my local development environment:
FROM public.ecr.aws/lambda/nodejs:16
RUN npm install --global yarn
WORKDIR /usr/app
RUN yarn install --frozen-lockfile
# where transpiled index.js is pointed.
VOLUME /var/task/build
CMD [ "build/index.handler" ]
I use the following Makefile with a develop target to run my lambda locally.
SHELL := /bin/bash
APPNAME = hello-world
.PHONY: develop
develop:
#docker build -f Dockerfile.dev -t $(APPNAME):dev .
#docker run -p 9000:8080 -v $(shell pwd)/build:/var/task/build $(APPNAME):dev & yarn develop
Lastly, this is how I test my lambda output locally:
cfaruki#hello-world[main] curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 102 100 100 100 2 161 3 --:--:-- --:--:-- --:--:-- 166
{
"statusCode": 200,
"headers": {
"content-type": "application/json"
},
"body": "{\"text\":\"hello world\"}"
}
With this context in mind, the issue I run into is what happens when I make a file change. If I change the response body to anything else, the file change is acknowledged in my terminal output. But the resultant output of my AWS lambda does not change.
docker run -p 9000:8080 -v /path/to/hello-world/build:/var/task/build hello-world:dev & yarn develop
yarn run v1.22.19
$ esbuild src/index.ts --watch --bundle --minify --sourcemap --platform=node --target=es2020 --outfile=build/index.js
01 Feb 2023 14:54:54,725 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/usr/app, handler=)
[watch] build finished, watching for changes...
01 Feb 2023 14:55:00,290 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
01 Feb 2023 14:55:00,290 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
START RequestId: 5b738544-3713-4b41-86f8-7eca4355d230 Version: $LATEST
END RequestId: 5b738544-3713-4b41-86f8-7eca4355d230
REPORT RequestId: 5b738544-3713-4b41-86f8-7eca4355d230 Init Duration: 1.35 ms Duration: 1143.56 ms Billed Duration: 1144 ms Memory Size: 3008 MB Max Memory Used: 3008 MB
[watch] build started (change: "src/index.ts") // <----- HERE IS THE CHANGE
[watch] build finished
I have validated that any change to my src/index.ts results in a change in build/index.js. I validate this by SSHing into the docker container and printing the file contents of build/index.js:
docker exec -it <CONTAINER-ID> /bin/bash
cat /var/task/build/index.js
It seems to me that the issue I am encountering is that the AWS Lambda docker image does not support live reloading of the function on file change. If that is the case, is there a way I can affect this behavior without adding another dependency to my development workflow?
Or is my only option to destroy and rebuild my docker image each time I make a file change? I am aware that docker-compose simplifies the process of rebuilding docker images. But I want to minimize the amount of configuration required by my project.

nodemon & nodeclipse wont autorestart on file change

I managed to setup nodeclipse with nodemon and I can now start my server.js script with monitor (nodemon) but something strance occurs:
On file change (even on the server.js) nodemon wont restart
In nodeclipse console I dont see the normal nodemon output, ex:
1 Aug 15:20:05 - [nodemon] v1.2.1
1 Aug 15:20:05 - [nodemon] to restart at any time, enter `rs`
1 Aug 15:20:05 - [nodemon] watching: *.*
1 Aug 15:20:05 - [nodemon] starting `node server.js`
PS: I' ve setup monitor path to nodemon.js which is installed with -g parameter
also I can not create any type of run configuration for "Node with monitor"
Is there any way to autorestart the server in nodeclipse even without nodemon if there isn't any other option...
After some time I ended up creating a Node application run configuration and simply added in the arguments tab -> Node arguments the path of nodemon.js
In my case : C:\Users\syd\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
Now I'm able to get console feed as well stop the node server from eclipse and auto restart on file changes :)

Node.js Forever is not creating Log files

2 nodejs scripts are being handled by forever. The system is using forever v0.11.1 and node v0.10.29
# forever list
info: Forever processes running
data: uid command script forever pid logfile uptime
data: [0] D34J userdown app/main.js 7441 10950 /root/.forever/D34J.log 0:2:31:45.572
data: [1] P0BX userdown app/main.js 11242 11261 /root/.forever/P0BX.log 0:2:20:22.157
# forever logs 0
error: undefined
# forever logs 1
error: undefined
Question: Why are the log files created by forever missing? Restarting the 2 processes still doesn't create any log files...
The directory /root/.forever does not show the log files too!
# ls -la /root/.forever
total 20
drwxr-xr-x 4 root root 4096 Jul 4 11:37 .
drwx------ 8 root root 4096 Jul 10 13:24 ..
-rw-r--r-- 1 root root 259 Jul 10 19:34 config.json
drwxr-xr-x 2 root root 4096 Jul 4 11:37 pids
drwxr-xr-x 2 root root 4096 Jul 10 17:12 sock
If you start your node process with forever your_script.js and don't specify a log file, forever will write your logs to the terminal (or cmd on Windows). The log file that is shown when you run forever list or forever logs does not reflect reality, since it's not created in that scenario. But if you specify log files, following the options:
-l LOGFILE Logs the forever output to LOGFILE
-o OUTFILE Logs stdout from child script to OUTFILE
-e ERRFILE Logs stderr from child script to ERRFILE
, like forever -l console.log -e error.log your_script.log, they will be created.
If you want forever to automatically create a log file for you, you have to start your script as a daemon, with forever start your_script.js. In this case, you can also specify your log files.
In the docs page you can see all the command line options.
To answer Shreejibawa (since I can't comment yet)...
forever is very sensitive to the order of the arguments. Take a look at their documentation and notice that the options must come before the script.
forever [action] [options] SCRIPT [script-options]
Instead of: forever start bin/www -e logs/error.log -l logs/logs.log
Try: forever start -e /path/to/logs/error.log -l /path/to/logs/logs.log your_script.js
I had the same problem in OSX. In OSX (at least), the command forever app.js starts the forever process in the foreground and doesn't write the log to file, even when -l and -e are provided. In this case, forever list lists the file even though it isn't there and forever logs i produces error: undefined.
When the forever DAEMON is started using forever start app.js, the log files do appear and can be viewed using forever logs i.

'500' error with sails.js 'testProject'

Went to http://sailsjs.org/#!getStarted and went through the steps the page requires. In my Win7 environment, I have node running and tested. I installed sails.js, changed directories, and 'sails lift'. Sails.js succeeds in launching and the CLI looks like:
$ sails lift
info:
info:
info: Sails.js <|
info: v0.9.7 |\
info: /|.\
info: / || \
info: ,' |' \
info: .-'.-==|/_--'
info: `--'-------'
info: __---___--___---___--___---___--___
info: ____---___--___---___--___---___--___-__
info:
info: Server lifted in `c:\Users\Dad\My Documents\Aptana Studio 3 Workspace\First Sails Project\t
estProject`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.
debug: --------------------------------------------------------
debug: :: Wed Nov 06 2013 14:06:25 GMT-0500 (Eastern Standard Time)
debug:
debug: Environment : development
debug: Port : 1337
debug: --------------------------------------------------------
But when I visit the port I get this on the page:
{
"status": 500,
"errors": [
"Failed to lookup view \"home/index\""
]
}
There is a very long trace at the CLI that begins:
error: Error rendering view at :: c:\Users\Dad\My Documents\Aptana Studio 3 Workspace\First Sails
Project\testProject/views/home/index
error: Using layout located at :: c:\Users\Dad\My Documents\Aptana Studio 3 Workspace\First Sails
Project\testProject/views/layout
error: Server Error (500)
error: Error: Failed to lookup view "home/index"
at Function.app.render (c:\Users\Dad\AppData\Roaming\npm\node_modules\sails\node_modules\expr
ess\lib\application.js:495:17)
.
.
.
The global install of sails.js went fine. All files are present in the views directory. I'm running node v0.8.18 and other apps I have run/render fine. Looking at the '500.js' file in the 'config' directory, if the 'view doesn't exist, just send json' (which is what seems to be happening). But the view does appear to exist so ... what am I missing?
this is a known issue on windows. check the work around in the linked issue or use sails 0.9.4 till the next release.

Node.js - "Uncaught Error: Cannot find module "redis""

I'm trying to build a simple "Twitter" style short messaging app in Node.js which uses Redis as the database (although I've heard that MongoDB might be easier)...
I have found a few links that point me in the direction of https://github.com/mranney/node_redis so I set up a new Node.js project using Brunch and ran the following in my project directory as instructed:
npm install redis hiredis
I then added the following from the auth.js example to vendor/script.js
var redis = require("redis"),
client = redis.createClient();
However when I run brunch w -s I get the following error in the console:
Uncaught Error: Cannot find module "redis"
I'm assuming that it's something to do with modules not being included into my project but I'm not really sure where to start. I added
"redis": "latest"
to my package.json file but that doesn't appear to do anything.
I also tried to install the redis module globally by running
sudo npm install -g redis
But still no luck.
I should also add that I have redis-server installed on OS X, and I can run it in the terminal:
$ redis-server
[2221] 17 Aug 10:48:42 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[2221] 17 Aug 10:48:42 * Server started, Redis version 2.4.13
[2221] 17 Aug 10:48:42 * The server is now ready to accept connections on port 6379
[2221] 17 Aug 10:48:42 - 0 clients connected (0 slaves), 922304 bytes in use
[2221] 17 Aug 10:48:47 - 0 clients connected (0 slaves), 922304 bytes in use
My application directory is a standard brunch install -
app
config.coffee
generators
node_modules
package.json
public
README.md
test
vendor
What am I doing wrong?
Brunch is html5 application assembler, not node.js, you can’t require node modules there.

Categories

Resources