gioru
gioru5mo ago

NODE_ENV always equates to 'development'

There must be something I don't know since NODE_ENV always equates to 'development' regardless of its value. In "use node" functions it works as expected. This happens both in convex development and production environments.
No description
4 Replies
Michal Srb
Michal Srb5mo ago
Right now we don't change the node_env value. If you need to distinguish your backends, I'd suggest you set up your environment variable with whatever values you need (this has the added benefit of allowing you to easily test your "prod" setup on your "dev" backend).
gioru
gioruOP5mo ago
Thanks for the answer Michal, yes was wondering if it was automatically handled by you but ok the cause must be somewhere else, maybe nextjs's. Temporarily solved by calling the variable "CONVEX_ENV"; needed to distinguish the environments for stripe checkouts. Can I ask you one more thing? Is it normal behaviour that I can't destructure single item queries?
export const getOne = internalQuery({
args: {
userId: v.id("users")
},
handler: async (ctx, { userId }) => {
const item = await ctx.db
.query("subscriptions")
.withIndex("byUserId", q => q.eq("userId", userId))
.unique()
return item
}
})
export const getOne = internalQuery({
args: {
userId: v.id("users")
},
handler: async (ctx, { userId }) => {
const item = await ctx.db
.query("subscriptions")
.withIndex("byUserId", q => q.eq("userId", userId))
.unique()
return item
}
})
const { _id } = await ctx.runQuery(internal.subscriptions.index.getOne, { userId })
const { _id } = await ctx.runQuery(internal.subscriptions.index.getOne, { userId })
Gives me type error: "Property '_id' does not exist on type '{ _id: Id<"subscriptions">; _creationTime: number; ...."
Michal Srb
Michal Srb5mo ago
The query returns Doc<"subscriptions"> | null, so you cannot destructure it because of the null case
ian
ian5mo ago
You can do const { _id} = (await ctx.db....unique())!; if you want to assume its existence it'll just throw a less useful error at runtime if it's missing

Did you find this page helpful?