How can i install 'ical' package in Node js in AWS Lambda? - node.js

I am trying to write a function for Alexa skill for reminders. I already wrote the Lambda function for that including ical declaration but whenever I execute that code it shows 'ical' module is not defined. Please can you give any solution.

Follow this steps to use npm packages in your lambda function.
Create a new folder for your application in your local machine. Ex. my-app
Add all your Javascript files and package.json.
Include all you npm dependencies in package.json
Install all npm modules using npm install. All node modules will be installed and npm_modules folder will be created inside your project.
Zip your complete project folder (my-app.zip)
Upload your zip file in aws lambda console
Finally execute your test & run your lamdba function.

Related

How to trace a npm module in AWS Lambda?

I have deployed the NestJS app to AWS Lambda, and there's an error message :
Cannot find module 'hbs'
PS :
Module hbs has been installed locally using npm install hbs --save
it's running well in my local
is there anyone who knows how to trace this issue in AWS Lambda? My feeling tells me that I have to trace this module in AWS Lambda, to make sure it's uploaded, but I don't know how to trace it.
You either have your lambda in and it's node_modules in s3 or you have your lambda deployed on a container using ECR , if it's the first case make sure you have the module in your node_module directory and if it's the second case make sure that you have your package in package.json and npm install in your Dockerfile.

Node.js Package.json file error while running Express.js

I am new to using Node.js
I have a project folder structure C:\A\B\C\
I have C:\A\B\C\html_pages\index.html in which I have React.js code having CDN
and C:\A\B\C\server.js which has Express.js code which I want to run.
I installed nvm then installed Node.js using command
nvm install 4.5
In windows PowerShell, I went to project directory
C:\A\B\C and used npm init (node_modules were not created in this step)
Did npm install express --save to use the express module (now node_modules folder was created but package.json was inside express folder)
Used npm start to start the web server but it gave following error.
ENOENT: no such file or directory, open 'C:\A\B\C\package.json'
I checked the posts on Stackoverflow for this error but was not able to solve it.
Should the package.json be generated directly under 'C:\A\B\C\ ?
I have installed Node.js in C:\Program Files\nodejs while project is not under Program Files, is this related to this?
P.S. : Used npm init --yes so that it installs node_modules inside my project folder and got the request processed but port 3000 gives error that it did not get GET request
The package.json file should be on the root of your directory.
Open command line from your root directory and type,
npm init
This will generate a package.json file on that directory.

Can I install an NPM package on AWS Lambda without having a local copy/development environment?

I'm using Amazon's web-based code editor to create a simple proof-of-concept, using node.js and Lambda.
I would like to install an NPM package, but I haven't found any way to do this-- if I used the Cloud 9 development environment, I'm able to get a terminal window which allows me to run NPM, but Cloud 9 isn't available in NorCal, where I want to place my code.
Every search that I run instructs me to install node.js on my local machine, create the project, then zip the file and upload it to Lambda.
Is there any way to run NPM without installing node.js locally? Or should I just consider moving to an environment where I can use Cloud 9?

How to install a node.js package using npm

I need help trying to install a node.js package from Github using the npm command prompt. It's an adaptive grid Jquery plugin called Masonjs: https://github.com/DrewDahlman/Mason.
It's my first time to use node.js, hence the difficulty understanding the setup instructions. I've CD'd to the project folder and run the 'install npm' and 'install bower' steps successfully, but I don't understand how to complete the remaining steps: running and building Gulp (is building necessary?).
Any help would be very much appreciated.
If you just want to use masonjs library in your project, you don't need to run gulp commands for running and building. Just cd into your project directory where you have initialized npm/bower and run npm install masonjs / bower install masonjs.
The next step would be to add the mason.js file in your index page. Now there would be different folder structure in which this mason.js file is present.
In case of npm module the path would be {your-project-directory}/node_modules/masonjs/lib
And in case of bower components the path would be {your-project-directory}/bower_components/MasonJS/dist
Now just use this library and it will work perfectly.

Best practice for distributing a nodejs command line application

How do people expect a nodejs commandline application to be organised when you distributed it via npm?
Would they expect to have to build it? Install it locally or globally? Should it always output a bin.js? Do you need some kind of alias / script to run it (via bin.js?).
Use the bin field in package.json to specify the entrypoint javascript file for your CLI.
Add #!/usr/bin/env node to the top of your entrypoint js file.
Specify the files which need to be packaged with your app, using the files field of package.json
In README, provide an npm install command line which a consumer can use to install your app, for example it could point at a github repository, or a package uploaded to the npm registry, which you can create with npm pack.
Upon installing the app locally or globally, a script will be created in the path (or locally in node_modules/.bin), which will let your command line app be run conveniently.

Resources