https://pulumi.com logo
#general
Title
# general
f

freezing-house-86375

02/19/2019, 8:18 AM
Hi guys
Copy code
import * as cloud from "@pulumi/cloud";
import * as pulumi from "@pulumi/pulumi";

const app = new cloud.API("my-app");

const config = new pulumi.Config();
const test = config.require("sendgrid_apikey");

// Serve a simple REST API on `GET /hello`:
app.get("/hello", async (_, res) => {
  res.json({
    cred: test
  });
});

export let url = app.publish().url;
That code, and this code
Copy code
import * as cloud from "@pulumi/cloud";
import * as pulumi from "@pulumi/pulumi";

const app = new cloud.API("my-app");

const config = new pulumi.Config();

// Serve a simple REST API on `GET /hello`:
app.get("/hello", async (_, res) => {
  res.json({
    cred: config.require("sendgrid_apikey")
  });
});

export let url = app.publish().url;
The first one works, but the second one throws error like this
Copy code
2019-02-19T15:13:34.381+07:00[                my-app1c06b73d] (node:1) UnhandledPromiseRejectionWarning: Error: Cannot find module '@pulumi/pulumi/runtime/index.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at /var/task/__index.js:238:23
    at __f3.__f4 (/var/task/__index.js:269:6)
    at __f3.<anonymous> (/var/task/__index.js:374:24)
    at __f3.__f14 (/var/task/__index.js:382:34)
    at /var/task/__index.js:451:22
    at Generator.next (<anonymous>)
g

gentle-diamond-70147

02/19/2019, 3:33 PM
Are these files in the same project or different projects? it looks like you need to run
npm install
for the second one to install the project's dependencies.
f

freezing-house-86375

02/20/2019, 3:31 AM
it’s the same
I also notice in this example, https://github.com/pulumi/examples/blob/4b978f90d0abfac5e3c8086f7c125a5b09972afa/cloud-js-twitter-athena/index.js . the
require
twitter
inside the
cloud.timer.interval
callback. Instead of importing it on top of the file. Is it somehow related? Can’t
config.require(..)
inside callback and have to
require
twitter
inside the callback?
5 Views